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

2025-01-06 00:57:27
推荐回答(4个)
回答1:

#include
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);
}

回答2:

#include
void main()
{
int n;

char str[100];

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

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

}

回答3:

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

回答4:

#include
main()
{
char s;int i;
scanf("%c",s);
while
[s!='\n';i++;i=0;]
printf("%d",i);
}