<分区>
好的,所以我正在尝试制作一个“读取字符”函数,它只接受大写或小写字母,而不是重音符号(我是法语,所以这对法语键盘很重要)并返回大写字母。 为此,我为 readcharacter 函数制作了另一个源文件:
char readCharacter()
{
char character;
do
{
printf("Please enter a letter without accents and hit 'enter': ");
character = getchar();
while(getchar() != '\n');
printf("\n");
character = toupper(character); //Upper-case if lower case
} while(((character < 65)||(character > 90)));
return character;
}
这是我的主要内容:
#include "main.h"
int main(void)
{
char MyLetter = readCharacter();
char MyLetter2 = readCharacter();
printf("%c\n%c\n", MyLetter, MyLetter2);
}
我的问题是,我的输出是这样的:
S
l
Please enter a letter without accents and hit 'enter':
Please enter a letter without accents and hit 'enter':
S
L
为什么我不明白?
Please enter a letter without accents and hit 'enter':S
Please enter a letter without accents and hit 'enter':l
S
L
不知道这是否相关,但我的 IDE 是 eclipse,编译器是 MinGW(gcc?) 抱歉英语不好和/或编码不好...我刚开始编码... 谢谢!