Create a c file in linux

1

I have a college assignment, which I am asked to implement a "C" program that produces files containing random integers of type long int , where random numbers must be between 0 and RAND_MAX . They must make files with the following number of random integers, for example: 50000.
This program must have an input parameter that is the number of integers to produce.
As I do not know where to start, I started to do the following code:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char * argv[])
{
FILE *fp;
fp = fopen("50000.c", "wb");
argv[50000];
fclose(fp);

}

Can someone give me some tips? This code is to be done later in the Linux terminal.

    
asked by anonymous 04.06.2016 / 16:51

1 answer

-1

Hello friend to run on linux using gcc just use the stdio.h library and nothing else.

I made a code where RAND_MAX can be changed in the define and ready, and by the way already knows how to use FILE.

I hope I have helped !!

 #include <stdio.h>
 #define RAND_MAX 100

    int main()
    {
        long numAleatorio;
        int i, vezes;

        numAleatorio = 0;
        i = 0;
        vezes = 0;

        printf("\nEntre quantos numeros aleatorios voce quer: ");
        scanf("%d", &vezes);

        while(i <= vezes)
        {
          numAleatorio = rand()%RAND_MAX;
          printf("\n%d", numAleatorio);
          i++;
        };

        printf("\n");

        return 0;
    }

To compile your face:

gcc teuCodigo.c -o nomeQualquerSemPontoC
./nomeQualquerSemPontoC

Example I do not care:

gcc test.c -o test
./test

Voila

    
01.07.2016 / 16:32