69,381
社区成员
发帖
与我相关
我的任务
分享
/**
@* Function name:find_char
@* Description:find a specific char in a string array
@* Input:strings: the string array where we search the char
value: the value of the char we need to search
@* Output:0: no matched char is found, 1: we can find the char we need
*/
int
find_char(char **strings, int value) {
assert(strings!=NULL);
/* 对于列表中的每个字符串进行查找 */
while(*strings!=NULL) {
/* 观察字符串中的每个字符,看看它是否是我们查找的那个 */
while(**strings!='\0') {
if (*(*strings)++ == value) {
return 1;
}
}
strings++;
}
return 0;
}
/* 程序用到的实参及调用 */
char *strings[]={"A string", "Another", "Third", "Last", '\0'};
int result=find_char(strings, 'T');