我得到了这段代码.. 现在具有挑战性的部分是我的教授要求我制作一个程序,要求用户输入一个大写的单词。
问题是,她希望程序自动将每个输入的字母转换为大写,即使用户的键盘没有处于大写锁定模式。所以我不知道我的程序到底出了什么问题……有人吗??帮助??我真的需要它..谢谢..
#include<stdio.h>
#include<ctype.h>
#include<string.h>
typedef char String[100];
main()
{
char Resp;
int l, x = 0, asc = 13;
String s, word1;
clrscr();
do {
printf("\n1st uppercased word: ");
do {
s[0] = getch();
word1[x++] = s[0];
strupr(s);
strcat(s, "\0");
puts(s);
} while (s[0] != (char) asc);
strcat(word1, "\0");
printf("\n\n1st word in lowercase: ");
for (l = 0; l < strlen(word1); l++)
putchar(tolower(word1[l]));
printf("\nDo you want to continue?[Y/N]: ");
Resp = getche();
} while (toupper(Resp) == 'Y');
getch();
return 0;
}
最佳答案
- 使用
getch()
获取用户的来信 - 使用
toupper()
将其转换为大写 - 用
putch()
显示它 - 转到 1
您可以添加一个断点---检查该字符是否为返回键并退出。
关于在 C 中将大写字母转换为小写字母..(具有挑战性的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3349219/