从键盘上输入一个字符串,统计字符串中的字符个数。不许使用求字符串长度函数strlen()。

如题所述

#include<stdio.h>
void main()
{
int i,n,m=0;
char a[100];
printf("请输入字符串:\n");
gets(a);
for(i=0;a[i]!='\0';i++)
m++;
printf("字符串的长度为:%d\n",m);
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2018-05-07
#include<stdio.h>
void main()
{
int n;

char str[100];

scanf("%s%n",str,&n);//注意%n不是%d,因此只需输入字符串即可得到n的值

printf("%s,字符串长度n=%d",str,n);

}
第2个回答  2011-04-25
Private Sub Command1_Click()
tmp = InputBox("请输入字符串", , "")
c = Len(tmp)
dx = 0
For i = 1 To c
If Mid(tmp, i, 1) >= "A" And Mid(tmp, i, 1) <= "Z" Then
dx = dx + 1
End If
Next
MsgBox "大写字母个数:" & dx
End Sub
第3个回答  推荐于2016-11-05
#include<stdio.h>
main()
{
char s;int i;
scanf("%c",s);
while
[s!='\n';i++;i=0;]
printf("%d",i);
}本回答被网友采纳