C语言中如何判断一个字符串中是否含有某个字符

include #include int charcontains(char str[],char c); int charcheck(char str[],char c); int main() { //int result = charcontains("maczhi",'i'); char name[] = "maczhis"; int result = charcheck(name,i); printf("%d\n",result); return 0; } int charcontains(char str[],char c) { //遍历整个字符 for (int i = 0; i < strlen(str); i++) { // 如果发现某个字符等于参数c 直接返回1,否则返回0 if(str[i] c) { return 1; } } // 说明str里面不含有字符c return 0; } int charcheck(char str[],char c) { int i = 0; // 遍历整个字符串 while (str[i]) { if (str[i] c) { return 1; } } return 0; } int char_check2(char str[],char c) { int i = 0; while (str[++i] != c && str[i] != '\0'); return str[i] != '\0 ';

Hibbs

0