十五周—计算字符串中字符种类个数

来源:互联网 发布:上海华腾软件怎么样 编辑:程序博客网 时间:2024/05/01 09:54
问题与代码:

文件名称:计算字符串中字符种类个数。

作者:邓哲

时间:2016年12月9日17:08:17

#include <stdio.h>#include <string.h>void fuction(char *);int main(){   char str[100];   gets(str);   char *ptr=str;   fuction(ptr);  return 0;}void fuction(char*str){    int i,number=0,bigletter=0,littleletter=0,others=0,len;    len=strlen(str);    for(i=0; i<len; i++)    {        if(str[i]>='0'&&str[i]<='9')        {            number++;        }        else if(str[i]>='A'&&str[i]<='Z')        {            bigletter++;        }        else if(str[i]>='a'&&str[i]<='z')        {            littleletter++;        }        else        {            others++;        }    }    printf("%d\n",bigletter);    printf("%d\n",littleletter);    printf("%d\n",number);    printf("%d\n",others);    printf("%d\n",len);}



知识点总结:函数声明可在main函数中该函数使用前,或者头文件里。

0 0
原创粉丝点击