This C code should generate 1 million random numbers, why is does it stop working during the execution process?
The libraries used are stdlib, stdio.h, and time.h
int main()
{
FILE *ofp;
int k=0, i=1000000;;
int array[i];
ofp=fopen("output.txt","w");
while (ofp==NULL)
{
printf("File is corrupted or does not exist, \nplease create or fix the file and press enter to proceed");
getchar();
}
srand(time(NULL));
rand();
for (k=0; k<1000000; k++)
{
array[k] = rand()%100;
fprintf(ofp, "%d\n", array[k]);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire