C语言警告提示
[Warning] incompatible implicit declaration of built-in function 'strlen' [enabled by default]
提示:strlen() 不兼容的函数声明(字符串长度函数)
位于头文件<string.h>
需要添加:#include <string.h>
#include <stdio.h> #include <string.h>
//strnchr(const char *str,char ch){
size_t strnchr(const char *str, char ch){
int i, n = 0, len = strlen(str); for(i=0; i<len; i++){ if(str[i] == ch){ n++; } } return n; } int main(){ char *str = "abcddtsfsdfdsf.net"; char ch = 't'; int n = strnchr(str, ch); printf("%d\n", n); return 0; }