You are on page 1of 1

#include<stdio.

h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
FILE *rand_arq;
if((rand_arq = fopen("meu_rand2.txt", "w+")) == NULL)
{
printf("Falha ao abrir o arquivo.\n");
exit(0);
}
fputs("Meu arquivo randomico...\n\n", rand_arq);

for(int i = 0; i < 1000; i++)


{
int nr_rand;
for(int j =0; j < 11; j++)
{
if(j == 0)
fprintf(rand_arq, "%05d\t", i);
else
{
nr_rand = rand()%100000L;
fprintf(rand_arq, "%05d",nr_rand);
if(j == 5)
putc('\t',rand_arq);
else
putc(' ',rand_arq);
}

}
putc('\n', rand_arq);
if(i > 0 && i%10==0)
putc('\n', rand_arq);
}
fclose(rand_arq);
printf("Arquivo randomico gerado.\n");

return 0;
}

You might also like