编写一个独立函数在多个字符串中查找某个字符,并判断该字符最先出现在哪个字符串中。
注:函数原型 int fun(char **,int n,char);
#include <stdio.h>
int find_char(char **strings, int n, char c) {
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; strings[i][j]; j++) {
if (strings[i][j] == c) {
return i;
}
}
}
return -1;
}
int main() {
char *strings[] = {"hello", "world", "goodbye"};
int n = sizeof(strings) / sizeof(strings[0]);
char c = 'o';
int index = find_char(strings, n, c);
if (index != -1) {
printf("Character '%c' found in string %d: %s\n", c, index, strings[index]);
} else {
printf("Character '%c' not found in any strings\n", c);
}
return 0;
}