我正在做一个程序,要求用户输入字符流并打印出大写和小写字母的数量。我想用一个函数来做到这一点,但遇到一些麻烦打印it..for进入即时得到0, 0
会感谢你的帮助,以了解每一个字符输入的IM,我做错了:打印大写/小写字母
#include <stdio.h>
#include <ctype.h>
int case_letters(int ch);
int main(void)
{
int x;
printf("please enter a some characters, and ctrl + d to see result\n");
case_letters(x);
return 0;
}
int case_letters(int ch)
{
int numOfUpper = 0;
int numOfLower = 0;
while ((ch = getchar()) != EOF)
{
if ((ch = isdigit(ch)) || ch == '\n')
{
printf("please enter a valid character\n");
continue;
}
else if ((ch = isupper(ch)))
{
numOfUpper++;
}
else if ((ch = islower(ch)))
{
numOfLower++;
}
}
return printf("%d, %d", numOfUpper, numOfLower);
}
谢谢分配!现在得到它:)是我怎么称呼功能是好的,但?在主要@meh – MNY
基本上,它很好。但是,我会删除参数,我会在函数中声明'ch',而不是在'main'中声明。然后在函数中再次打印消息,而不是在'main'中。换句话说,我会写这样的'main':'int main(void){case_letters();返回0; }'。 –
感谢您的反馈!@meh – MNY