从键盘敲入一个任意字符串,用一位数组存放起来,咋表示呢?
最终目的是要统计一个任意字符串中数字的个数
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernelbase.dll', no matching symbolic information found.
The thread 0x11F4 has exited with code 11 (0xB).
The program 'C:\Users\Administrator\Desktop\新建文件夹\C语言\Debug\Cpp1.exe' has exited with code 11 (0xB).
函数功能:输入一字符串(换行为结束标志)统计其中数字(0,1,2,…,9不单独统计)、空白和其它字符出现的次数。
#include <stdio.h>
int main(int argc, char *argv[])
{
char c;
int digit = 0, blank = 0, other = 0;
while((c = getchar()) != '\n')
{
if((c >= '0') && (c <= '9'))
{
digit++;
}
else if((c == ' ')||(c == '\t'))
{
blank++;
}
else
{
other++;
}
}
printf("数字个数digit=%d 空白个数blank=%d 其他字符个数other=%d\n",digit,blank,other);
return 0;
}
#include
main()
{
char str[50];
int i=0,num=0;
printf("请输入一个任意字符串:");
gets(str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]='9') num++;
}
printf("共有数字%d个",num);
}
这样对吗?
可以输入字符串,但不输出
状态栏显示看最上方问题补充,望继续解答!!