如何检查字符串是否包含特定的给定字符?
答案 0 :(得分:2)
#include <stdio.h>
#include <string.h>
int main()
{
const char* haystack = "self";
const char needle = 'l';
size_t len = strlen(haystack);
size_t i;
for(i = 0; i < len; i++) {
if(haystack[i] == needle) {
fprintf(stdout, "Found char '%c' in '%s' at position %d\n", needle, haystack, (i+1));
break;
}
}
return 0;
}