do while with strstr Statment

It's been a long time since I coded anything. I'm having problems checking the equalty of a string function within a "while" statement. The loop never seems to evaluate the strstr result.

If I test with an integer value it works so I assume I don't have a brace out of place elsewhere in my code. I'm trying to loop until a predetermined sub string is found.

do
{
fgets( buffer, 255, fptr );

c--; // while statment test
//}while( c>1 ); // until string found
}while( (strstr(buffer, " "))==NULL ); // until string found
if you're lookink for space as substring, you'd better have condition like while(strstr(buffer, " ")). It'll loop until space is found
I've tried,

while( strstr(buffer, " ") );

and it executes once even though "buffer" does not contain the sub string.

I've tried,

while( !strstr(buffer, " ") );

and its an infinite loop even when the sub string is encountered.

Is there a compiler setting I may have wrong. the logic works with the integer 'c' just not the function. is the returned pointer not understood?
but this works?

char* str;

str=" [";

while( strstr(buffer, str) );

what is so different between using quotes to define a sub string and a pointer to a sub string?
I wonder if it's the fegets() that is your problem. It says here http://www.cplusplus.com/reference/clibrary/cstdio/fgets/ that fgets() puts a null character at the end of the string to signal the end of reading. Just do a cout test to see everything that is read into buffer, comment everything else out for a this test. What do you think, worth a shot?
Last edited on
Topic archived. No new replies allowed.