i got a problem with this code...
i cant find the problem so i posted here...
the problem is that this program only reads EVERY OTHER LINE of a file...
im new to file handling, sorry....
Code:
#include <stdio.h>
int main(void)
{
FILE *file = fopen("Data/Strings.txt", "a+");
char string[100];
clrscr();
if(file == NULL)
{
printf("\n\nError creating/reading file.\n");
printf("The directory/file may not exist.\n");
getche();
return 0;
}
else
{
printf("\n\nFile was created/read successfully.\n");
printf("\nEnter a sentence to be appended to the file:\n\n");
gets(string);
fputs(string, file);
fputs("\n", file);
rewind(file);
printf("\n\nThe contents of Strings.txt is:\n\n");
while(fgets(string, 100, file) != NULL)
{
printf("%s", fgets(string, 100, file));
}
fclose(file);
}
getche();
return 0;
}