Mam taki prosty pliczek alk.txt:
beer
vodka
wine
whisky
Chciałbym go odczytać linijka po linijce - i robię to tak:
FILE *stream;
char *s;
stream = fopen("alk.txt", "r");
while(!feof(stream)) {
fscanf(stream, "%s", s);
printf("%s", s);
}
fclose(stream);
lub tak
FILE *stream;
char *s;
stream = fopen("alk.txt", "r");
while(fgets(s, 255, stream) != NULL) {
printf("%s", s);
}
fclose(stream);
Jak kompilowałem GCC pod Windows 10, to działało prawidłowo. Skompilowałem pod Windows 7 i mam taki wynik (dla obu kodów źródłowych):
$ "$ "$ "$ "