网站建设资讯

NEWS

网站建设资讯

c语言判断字符个数的函数 c语言中判断数字的函数

用c语言如何判断一个字符串常量的字母个数,数字个数,空格个数,其他个数

下面是我的程序:

创新互联公司一直在为企业提供服务,多年的磨炼,使我们在创意设计,全网整合营销推广到技术研发拥有了开发经验。我们擅长倾听企业需求,挖掘用户对产品需求服务价值,为企业制作有用的创意设计体验。核心团队拥有超过10多年以上行业经验,涵盖创意,策化,开发等专业领域,公司涉及领域有基础互联网服务移动服务器托管APP应用开发、手机移动建站、网页设计、网络整合营销。

#include

#define

n

81

#include

int

main()

{

char

str[n];

int

i,n,zimu,num,kongge,others;

zimu=num=kongge=others=0;

gets(str);

n=strlen(str);

for(i=0;i

='a'str[i]='z')

zimu++;

else

if(str[i]='a'str[i]='z')

zimu++;

else

if(str[i]='0'str[i]='9')

num++;

else

if(str[i]='

')

kongge++;

else

others++;

printf("\n字母:%d,数字:%d,空格:%d,其他:%d",zimu,num,kongge,others);

return

0;

}

希望对你有所帮,记得采纳哦。

C语言如何判断 某个字符串中有多少字符?

是这样的结果吗,有问题追问,看程序:

#include stdio.h

#include string.h

main()

{

char c[20];

int i=0,j=0,k=0,l=0,h=0;

printf("请输入一个字符串:");

gets(c);

for(i=0;i=strlen(c);i++)

{

if(c[i]='0'c[i]='9')

j++;

if((c[i]='a'c[i]='z') || (c[i]='A'c[i]='Z'))

k++;

if(c[i]==' ')

l++;

if((c[i]32c[i]=47)||(c[i]=58c[i]=64)||(c[i]=91c[i]=96)||(c[i]=123c[i]=126))h++;

}

printf("数字有%d个\n",j);

printf("字母有%d个\n",k);

printf("空格有%d个\n",l);

printf("其它字符有%d个\n",h);

return 0;

}

C语言中如何判断字符长度???

使用string库函数里的strlen函数即可判断字符长度。

strlen函数可以计算给定字符串的长度,返回值为长度值。

例如计算字符串“helloworld2017”的长度的代码:

#includestdio.h

#includestring.h

int main()

{

int i;

i = strlen("helloworld2017");

printf("%d",i);

}运行结果如下:


网站名称:c语言判断字符个数的函数 c语言中判断数字的函数
分享URL:http://cdweb.net/article/hpsoic.html