#define MAXLINE 1000
char pattern[] = "ould";
main()
{
char line[MAXLINE];
int found = 0;
while (getline(line,MAXLINE) > 0)
if (strindex(line, pattern) >= 0 ) {
printf("%s", line);
found ++;
}
return found
}
Why does that while loop go on forever? getline(line,1000) would, as I barely understand it, return the length of the line, and "append it" (?) to MAXLINE, making a number larger than 1000, depending on the line length... why would that ever dip below zero?
I read that getline returns -1 if "unsuccessful", when would that be? When would line not be read?
This is on page 69 of Kernighan. I've been skipping around the book, and I'm currently backtracking to see where I missed something.
"Describe what you tried, what you expected to happen, and what actually resulted. Minimum 20 characters."