/////// strmatch.C /////// #include int string_match(char str[], char line[]) { if ( str[0] == '\0') // str is empty { cerr << "string_match: empty match string\n"; return(-1); } for (int i = 0 ; line[i] != '\0' ; i++) { if ( line[i] != str[0] ) // first chars different continue; // skip rest of loop body // compare remaining characters // untill first mismatch or end of string for ( int j = i + 1, k = 1; line[j]==str[k] && str[k] != '\0'; j++, k++ ) { } if ( str[k] == '\0') // end of str is reached return(1); // successful match else if (line[j] == '\0') // end of line is reached return(0); // no match possible any more } return(0); // failed to match }