【发布时间】:2017-05-13 14:08:51
【问题描述】:
我刚开始学习 C 语言的循环。
编写一个程序,检查输入的abc字母是否正确,输入的是abc字母的小写字母,假设输入是有序的,如果遗漏了一些后者你应该在缺失的后者后面加上大写。输入有一个 $ 符号。
例子:
对于输入:abcdijklmnstuvyz$ 应该打印 abcdEFGHijklmnOPQRstuvWXyz
对于输入:abefghijkopqrvwxyz$ 应该打印 abCDefghijkLMNopqrSTUvwxyz
我的想法是在 'a,b,c' 字母表上使用两个数组,在更正后使用另一个数组,这是我的代码:
#include <stdio.h>
int main()
{
char student[26] = {0};
char real[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 'c', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char corection[26] = {0};
int istudent = 0, ireal = 0, icorection = 0;
for(istudent = 0; istudent<26; istudent++)//changed to < instad of <=
scanf("%c", &student[istudent]);
for(istudent = ireal = icorection = 0; (istudent < 26) && (ireal < 26); icorection++)
{
if (student[istudent] == real[ireal])
{
istudent++;
ireal++;
corection[icorection] = student[istudent];
}
if (student[istudent] != real[ireal])
{
istudent++;
ireal++;
corection[icorection] = (real[ireal] - 32);
}
}
// print results
int k;
printf("printed array: \n");
for(k=0;k<26;k++)
printf("%c", corection[k]);
return 0;
}
我正在尝试打印结果以检查我是否编写了正确的代码,但它没有显示正确的输出
【问题讨论】:
-
抱歉,有什么问题?
-
现在是开始学习如何使用调试器的好时机。