【发布时间】:2017-09-15 07:44:20
【问题描述】:
我正在尝试创建一个程序,要求用户首先输入他们想要从小写转换为大写的值的数量。然后 for 循环将每个值分配到一个数组中。然后数组通过另一个 for 循环使用 LowerToUpper 函数将值转换为大写。
当我去运行程序时,它会接受值,然后在命令窗口中开始将它们加倍,当你完成输入值时会停止,而不是 printf 结果。你能解释一下为什么吗。提前谢谢你
#include<stdio.h>
#include <string.h>
#include <ctype.h>
void LowerToUpper(char* array)
{
toupper(*array);
}
int main(void)
{
int i, amount;
printf("How many values?\n");
scanf("%d", &amount);
char *d;
char array1 [amount];
printf("Please enter the values\n");
for(i=0; i<amount; i++)
{
scanf("%c", &array1[i]);
}
for(i=0; i<amount; i++)
{
d=&array1[i];
LowerToUpper(d);
scanf("%c", &array1[i]);
printf("%c", array1[i]);
}
return 0;
}
【问题讨论】:
-
Toupper和toupper不是同一个东西,只是说说而已。 -
toupper不会将某些内容更改为大写;如果可用,它返回一个大写转换。实际的输入参数没有改变。 -
@WhozCraig 以 4 秒的优势击败了你。 :)
-
你的
LowerToUpper函数有什么用?除了提到您使用toupper的问题之外,它并没有真正做任何有用的事情。为什么不直接拨打toupper? -
我也不明白你为什么将输入读入
array1两次?特别是因为第二次阅读会(在您解决toupper问题后)将覆盖您刚刚大写的字符。