How indeed!
You show two separate arrays holding different numbers of elements.
Without arcane calculations attempting to use a single loop counter, the simplest way would be to scan each separately using a function.
#include <stdio.h>
#include <string.h>
int srch( char *name, char **list, size_t lsz ) {
for( size_t i = 0; i < lsz; i++ )
if( strcmp( name, list[i]) == 0 )
return 1;
return 0;
}
int main( void ) {
char* name[] = {"Bill", "Charlie", "Fred"};
char* name2[] = {"George", "Ginny", "Percy", "Ron"};
if( srch( "Ron", name, sizeof name /sizeof name[0] )
|| srch( "Ron", name2, sizeof name2/sizeof name2[0] ) ) {
printf("Found\n");
return 0;
}
printf("Not found\n");
return 1;
}
EDIT:
In the spirit of the season, here is an alternative to the above. Note the ease with which a third list can be added to the possibilities.
#include <stdio.h>
#include <string.h>
int srch( const char *name, const char **list, const size_t lsz ) {
size_t i = 0;
while( i < lsz && strcmp( name, list[i] ) ) i++;
return i < lsz;
}
int main( void ) {
const char* name1[] = { "Dasher", "Dancer", "Prancer", "Vixen", "Comet" };
const char* name2[] = { "Cupid" };
const char* name3[] = { "Donner", "Blitzen", "Rudolph" };
const char *guide = "Rudolph";
int found =
srch( guide, name1, sizeof name1/sizeof name1[0] )
|| srch( guide, name2, sizeof name2/sizeof name2[0] )
|| srch( guide, name3, sizeof name3/sizeof name3[0] )
;
printf( "%sound\n", found ? "F" : "Not F" );
return !found; // 0 for success; 1 for failure.
}