搜索
首页 电脑/网络 程序设计 C/C++

C语言程序题

写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,在主函数中输入字符串以及输出上述的结果。

全部回答

2004-11-13

0 0

    void stat(char *str) { int n1,n2,n3,n4; n1 = n2 = n3 = n4 = 0; while (*str) { if ((*str >= 'a' && *str = 'A' && *str = '0' && *str <= '9') n2++; else if (*str == ' ') n3++; else n4++; str++; } printf("the string has %d letters, %d numbers, %d spaces and %d other characters。
    \n", n1, n2, n3, n4); } void main() { char str[51]; printf("please enter the string (no more than 50 characters): "); scanf("%[^\n]", str); //仅当回车时才读入整个字符串,如果用%s则会在遇到空格时就读入字符串了。
     stat(str); } 。

2004-11-14

498 0

    对楼上的略作修改: #include #include void stat(char *str) { int n1,n2,n3,n4; n1 = n2 = n3 = n4 = 0; while (*str!='\0') { if ((*str >= 'a' && *str = 'A' && *str = '0' && *str <= '9') n2++; else if (*str == ' ') n3++; else n4++; str++; } printf("the string has %d letters, %d numbers, %d spaces and %d other characters。
    \n", n1, n2, n3, n4); } void main() { char str[51]; clrscr(); printf("please enter the string (no more than 50 characters): \n"); gets(str); stat(str); getch(); } 。
    。

2004-11-13

493 0

    #include "stdio。h" #include "ctype。
    h" main() { char c[256]="grw etG&&HG&^(*&^&( 9 8 7 86Hrtghh"; register int i; int a=0,n=0,s=0,o=0; for(i=0;i<256;i++) { if(c[i]=='\0') i=256; if(isalpha(c[i])) a++; else if(isdigit(c[i])) n++; else if(isspace(c[i])) s++; else o++; } printf("Alpha:\t%d\nNumber:\t%d\nSpace:\t%d\nOthers:\t%d\n",a,n,s,o); }。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
C/C++
硬件
电脑装机
程序设计
互联网
操作系统/系统故障
笔记本电脑
反病毒
百度
软件
程序设计
C/C++
VB
数据库
汇编语言
JAVA相关
VC++
C#/.NET
其他编程语言
C/C++
C/C++
举报
举报原因(必选):
取消确定举报