whd
whd

Reputation: 1861

Reads only alphabetic chars with fscanf

Hello i have simply function to read from file

while(fscanf(fp," %255[a-zA-Z]",test) == 1)
{
    puste = 1;
    push(&drzewo,test);
}

It should read only words which contains only alphabetic characters and that works great. When I have for example a single number in my file my while loop quits; how should I change it?

Upvotes: 1

Views: 247

Answers (1)

unwind
unwind

Reputation: 399949

Of course it stops, since the fscanf() call will fail to do the conversion you're requiring, and thus return 0. What would you expect it to do?

It's often better to read whole lines using fgets(), and then parse them "manually", that way it's easy to just do nothing and read another line if the desired data is not found.

Upvotes: 1

Related Questions