1.数组 问题:如何输入n个整数,使按下回车结束。# include <stdio.h>
main()
{
int a[100],b=0,c;
while (a[b] != '\n')
{
scanf("%d",&a[b]);
b++;
}
for(c=0;c<b;c++)
{
printf("%d",a[c]);
}
}
我发现我这样写 回车根本停止不了,是因为‘\n’是字符,我定义是整形原因吗?
2.函数问题:可以返回多个值 给 main函数吗?
比如统计一个字符串 空格 字母 其他的个数,结果在main 函数输出# include <stdio.h>
# include <string.h>
int str(char a[100])
{
int i,eng=0,num=0,blank=0,other=0;
for(i=0;i<strlen(a);i++)
{
if((a[i] >= 'A' && a[i] <= 'Z') || (a[i]>='a')&&(a[i]<='z'))
eng++;
else if(a[i] == ' ')
blank++;
else if(a[i]>='0' && a[i]<= '9')
num++;
else
other++;
}
// return 这里我不知道该如何返回值,好像这里只能返回一个,但结果有4个
}
int main()
{
char str1[100];
gets(str1);
printf("%d",str(str1));
//在这里 接受统计出的值,并打印,有4个值,该如何接受
}
|