I just started to learn loops on C language.
Write a program that checks if the input of abc alphabet is correct, the input is small letters form abc alphabet, asume that the input is orderd, if misissing some latters you should add the missing latter with capital.in the end of the input there is a $ sign.
exampls:
for the input: abcdijklmnstuvyz$ should print abcdEFGHijklmnOPQRstuvWXyz
for the input: abefghijkopqrvwxyz$ should print abCDefghijkLMNopqrSTUvwxyz
my idea was to use two arrays on for the 'a,b,c' alphabet and another after correction, here is my code:
#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;
}
I'm tring the print the result to check if I wrote a correct code, but it doesn't show me the correct output