I am currently trying to create a file with a text and then read the file and print it on my screen.My current code is this:
int main(){
char s[10][100];
FILE *fpointer;
fpointer=fopen("file.pp","w");
int i=0
while(i<10){
printf("enter a sentence:\n");
gets(s);
fprintf(fpointer,"%s\n", s);
x++;
}
fpointer=fopen("file.pp","r");
int i=0;
for(i=0;i<10;i++){
fgets(s[i],100,fpointer);
printf("the %d sentence is: %s \n",i+1,s[i]);
}
if(fpointer==NULL){
fprintf(stderr,"mistake");
EXIT_FAILURE;
}
fclose(fpointer);
return 0;
}
The creation of the file works fine, same with the creation of the text. My problem is the reading of the contents: the first line is displayed correctly followed by the rest of the lines that are just a bunch of symbols. I would imagine that the problem is the way I use fgets
but I can't seem to be able to resolve it.