c语言关于字符串的操作编写

2012-11-01 15:45:11 · 作者: · 浏览: 316
    程序要求:
   
    统计字符串的字符总数,及统计大写、小写字母的数目。并将数目打印到屏幕
   
    程序如下:
   
    #include <stdlib.h>
   
    #include <stdio.h>
   
    #include <apue.h>
   
    #include <errno.h>
   
    #include <apueerror.h>
   
    int main(int argc,char *argv[])
   
    {
   
    char buf[100];
   
    int len,sum;
   
    int A,a=0;
   
    fgets(buf,sizeof(buf),stdin);
   
    buf[strlen(buf) - 1] = 0;
   
    sum = togeher(buf);
   
    printf(“th sum = %d\n”, sum);
   
    A = uppersum(buf);
   
    printf(“the upper letter =%d\n”,A);
   
    a=lowsum(buf);
   
    printf(“the low letter=%d\n”,a);
   
    return 0;
   
    }
   
    int togeher(char *str)
   
    {
   
    int len = 0;
   
    while(*str != '\0‘)
   
    len ;
   
    return len;
   
    }
   
    int uppersum(char *str)
   
    {
   
    int Alen = 0;
   
    while(*str != '\0’)
   
    {
   
    if(*str >= 'A' && *str <= 'Z‘)
   
    Alen ;
   
    }
   
    return Alen;
   
    }
   
    int lowsum(char *str)
   
    {
   
    int alen=0;
   
    while(*str !='\0’)
   
    {
   
    if(*str >= 'a'&&*str <= 'z‘)
   
    alen ;
   
    }
   
    return alen;
   
    }