lets say i there is a file with 2 lines in it. and we going to read from it.

only thing we dont how how many spaces there are. for ex " -hello ", "    -hello", "-hello", "  -hello    "



 file.txt
-----------
     -hello 
-hello 29 
-----------

i want to skip line that has only "-hello" in it, NOT "-hello 29"

the way i was think was

char line[20];

//read one line at a time

while((fget(line, 20), finp1)!= NULL)
{
    if(strcmp(line, "-hello") != 0)
       {
           //HERE LINE SHOULD HAVE THE VALUE "-hello 29";
       }
}

strcmp() won't work for you because it expects an exact match.

you can call strstr() to see if the line contains "-hello". If it does, then check for anything following to see if something other than spaces. You may need to do additional checks if there is a chance that the line will contains other stuff, for example "-HelloWorld" because strstr() will return valid pointer for that also.

char* ptr = strstr(line, "-hello");
if( ptr != NULL)
{
   // now check remainder of string to see if 
   // there is anything but spaces following the
   // text -Hello.
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.