k-man
k-man

Reputation: 1211

fgets dont return NULL when no new line found

well i'm using while loop:

while(fgets(pclientRow, 1024 , f) != NULL)

in other classes it works ok, but in one of them, when i'm reading from file line by line, it won't get out of the loop even when the lines end, i saw that in the debugger.

why is it? and it was working even in that class before and now i dont know why it keep bringing empty lines untill it's crshing..

any idea?

Upvotes: 1

Views: 2051

Answers (2)

davissp14
davissp14

Reputation: 775

You could catch the \n issue by placing something like this in your while loop.

if((int)strlen(pclientRow) == 1) break;

Upvotes: 0

user411313
user411313

Reputation: 3990

fgets in a standard ANSI C function, see documentation: Here fgets read max. 1023 character up to next '\n' or EOF. Your lines are longer than 1023 character or the last line has no terminating newline.

Upvotes: 3

Related Questions