直接使用strlen就可以了,比如下面
#include #include int main(){ char str[1010]; gets(str); printf("%d\n", strlen(str)); return 0;}