方法一:
#include<stdio.h>
int length(char *s){char *p=s;while(*p!='\0'){ //等同于 *pp++;}return p-s;
}
void main(){char s[32];printf("请输入一个字符串:");scanf("%s",&s);printf("长度为:%d",length(s));
}
 
方法二:
#include<stdio.h>
int length(char *s){char *p=s;while(*p++);return p-s-1;
}
void main(){char s[32];printf("请输入一个字符串:");gets(s);printf("长度为:%d",length(s));
}
 


















