So I want to use a for loop to read in 10 different numbers into a text file. The problem with my program is that it crashes while inputting the 4th number. How do I fix this? Here is my code:
#include <stdio.h>
#include <stdlib.h> /* For exit() function */
int main()
{
int x[20], i;
FILE *fptr;
fptr=fopen("line.txt","w");
printf("Enter numbers\n");
for (i=0; i<10; i++){
gets(x[i]);
}
fprintf(fptr,"%d", x);
fclose(fptr);
return 0;
}