Write a separate function that checks whether a name starts with the listed strings.
For example
#include <stdio.h>
#include <string.h>
int start_with( const char *s, const char * a[] )
{
int success = 0;
s += strspn( s, " \t" );
for ( ; *a != NULL && !success; ++a )
{
success = memcmp( s, *a, strlen( *a ) ) == 0;
}
return success;;
}
int main(void)
{
const char *title[] = { "Mr.", "Ms.", "Mrs.", NULL };
enum { N = 100 };
char name[N];
do
{
printf( "Input Customer's Name [must have %s or %s or %s: ", title[0], title[1], title[2] );
name[0] = '\0';
fgets( name, N, stdin );
name[strcspn( name, "\n" )] = '\0';
} while ( !start_with( name, title ) );
puts( name );
return 0;
}
The program output might look like
Input Customer's Name [must have Mr. or Ms. or Mrs.: Bob
Input Customer's Name [must have Mr. or Ms. or Mrs.: Mr. Bob
Mr. Bob