C语言:编写一个函数,由实参传来一个字符串,统计此字符串中字母,数字,空格和其他字符的个数。
#include<stdio.h>intmain()charch[100];voidsum(charch[100]);inti;gets(ch);sum(ch[100])...
#include <stdio.h>
int main()
char ch[100];
void sum(char ch[100]);
int i;
gets(ch);
sum(ch[100]);
puts(ch);
void sum(ch[100])
{int character=0,number=0,others=0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))character++;
else if(ch>='0'&&ch<='9')number++;
else others++;}
i++;
return(character,number,others);
}
}
哪里错了?应该怎么改 展开
int main()
char ch[100];
void sum(char ch[100]);
int i;
gets(ch);
sum(ch[100]);
puts(ch);
void sum(ch[100])
{int character=0,number=0,others=0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))character++;
else if(ch>='0'&&ch<='9')number++;
else others++;}
i++;
return(character,number,others);
}
}
哪里错了?应该怎么改 展开
2013-12-16
展开全部
!!!你确定这个是程序?!?一会ch[]一会ch~~肯定不对啊~而且你函数调用格式也不对啊~~~重写吧~~~思密达~~~
#include <stdio.h>
void sum(char ch[]);
int main()
{
char ch[100];
gets(ch);
puts(ch);
sum(ch);
printf(...);
}
void sum(char ch[])
{
int character=0,number=0,others=0;//定义全局才能在主函数里也用滴~~~
int i=0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z'))
character++;
else if(ch[i]>='0'&&ch[i]<='9')
number++;
else others++;
}
i++;
// return(character,number,others); void怎么能返回值呢?
}
至少调整下你的顺序吧~~自己再看看怎么改~~~
#include <stdio.h>
void sum(char ch[]);
int main()
{
char ch[100];
gets(ch);
puts(ch);
sum(ch);
printf(...);
}
void sum(char ch[])
{
int character=0,number=0,others=0;//定义全局才能在主函数里也用滴~~~
int i=0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z'))
character++;
else if(ch[i]>='0'&&ch[i]<='9')
number++;
else others++;
}
i++;
// return(character,number,others); void怎么能返回值呢?
}
至少调整下你的顺序吧~~自己再看看怎么改~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看改好的,有不懂的欢迎追问。
#include <stdio.h>
int main()
{
char ch[100] = "";
void sum(char* ch);
gets(ch);
sum(ch);
puts(ch);
return 0;
}
void sum(char *ch)
{
int character=0,number=0,others=0;
int i = 0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z'))character++;
else if(ch[i]>='0'&&ch[i]<='9')number++;
else others++;
i++;
}
printf("character:%d\tnumber:%d\tothers:%d\n",character,number,others);
}
#include <stdio.h>
int main()
{
char ch[100] = "";
void sum(char* ch);
gets(ch);
sum(ch);
puts(ch);
return 0;
}
void sum(char *ch)
{
int character=0,number=0,others=0;
int i = 0;
while(ch[i]!='\0')
{
if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z'))character++;
else if(ch[i]>='0'&&ch[i]<='9')number++;
else others++;
i++;
}
printf("character:%d\tnumber:%d\tothers:%d\n",character,number,others);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |