char *test = "This is a test"; //***************************************************************************** // This routine searches the string "ptr" for the character "val". // It returns the address of the first occurance of "val" if found. // Otherwise, it will return the address of the NULL at the end of the string. //***************************************************************************** char *FindChar(char *ptr, int val) { while (*ptr) { if (*ptr == val) break; ptr++; } return ptr; } //***************************************************************************** // This routine searches a string for the letter "A". If "mode" is zero, the // string pointed to by "str" will be searched. Otherwise, the global variable // "test" will be searched. This routine uses FindChar to do the search. //***************************************************************************** char *FindA1(char *str, int mode) { char *ptr; if (mode == 0) ptr = FindChar(str, 'a'); else ptr = FindChar(test, 'a'); return ptr; } //***************************************************************************** // This routine searches a string for the letter "A". If "mode" is zero, the // string pointed to by "str" will be searched. Otherwise, the global variable // "test" will be searched. This routine does not use FindChar to do the // search. //***************************************************************************** char *FindA2(char *str, int mode) { int i = 0; char *ptr; int val = 'a'; if (mode == 0) { while (str[i]) { if (str[i] == val) break; i++; } ptr = &str[i]; } else { while (test[i]) { if (test[i] == val) break; i++; } ptr = &test[i]; } return ptr; }