这个程序能检测单行字符长度吗?

#include
int main()
{
char s;
scanf("%c",&s);
int i,x;
for(i=2;getchar()!='\n';i++)
x=i;
printf("%d\n",x);
}

如果你要用scanf输入字符串,应该这样用
char buf[128]={'\0'};
scanf("%s", buf);
不过scanf不是安全函数,应该用scanf_s

之后再用strlen检测输入字符串的长度。