#include <
stdio.h>
int count(char*p){
int cnt = 0;
while(*p){
if(*p >= 'a' && *p <= 'z')
cnt++;
p++;
}
return cnt;
}
int main(){
char buf[100] = "sd12df";
printf("%d\n", count(buf));
return 0;
}
追问为什么要写“while(*p)”?
追答*p得到p所指向的字符,当该字符不为'\0'(ascii码值为0)时继续循环