Witam,
mam problem z prostą rzeczą,
mój cel:
czytanie pliku słowo po słowie z uwzględnieniem nowych linii,
robie to tak:
char *getWord(FILE *fp)
{
int n = 0;
char word[100];
int ch;
while(ch = fgetc(fp))
{
if(ch == EOF)
return NULL;
else if(ch == '\n')
{
word[n++] ='\n';
break;
}
else if(ch == ' ')
{
word[n++] = ' ';
break;
}
else if(isalpha(ch))
word[n++] = ch;
else continue;
}
if(!n) return NULL;
return strdup(word);
}
mój tekst:
czesc siema
hey
jestem tutaj
wychodzi:
czesc siema
iema hey
a jestem tutaj
Z góry dzięki za pomoc i naukę.