I'm making a C code that generates a very large random number(say 50 digits), and then store it in the string buffer and copy this to a text file. Please refer the code that I have written for the same:
FILE *fp;
char first_num[MAX];
char second_num[MAX];
char *answer;
int i,test_cases,numbers;
fp = fopen("data.txt", "w+");
if(fp==NULL)
{
printf("Error opening file\n");
exit(1);
}
printf("How many number combinations you wish to enter?\n");
scanf("%d",&numbers);
for(i=0;i<(2*numbers);i++)
{
char buf1[50], *number;
number = rand() % 100000000000000000000000000000000000000000000000000000000000000000000000;
sprintf(buf1, "%s", number);
fprintf(fp,"%s",buf1);
}
fclose(fp);
But I get a floating point exception and my code is dumped. Can anyone help me out in the same. I'm actually trying to multiply those random numbers once they are stored in the file as strings.
Aucun commentaire:
Enregistrer un commentaire