Is It You, Cody?
by CodeChum Admin
Can you identify if Cody's name is spelled right? If so, then make a program that accepts four one-letter strings separated by space and print "Correct" if the inputted strings, combined in order, spell the name Cody correctly. If not, print "Wrong". It doesn't matter if it's in uppercase or lowercase, as long as it's spelled correctly, it's considered correct.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
int i, check;
char str[15];
char name[5] = "cody";
char *istr;
printf("\nEnter name (separated by space): ");
gets(str);
istr = strtok(str, " ");
check = 0;
i =-1;
while (istr!= NULL)
{
i++;
if (i>3)
{
check = 1;
break;
}
if (name[i] != tolower(*istr))
{
check = 1;
break;
}
istr = strtok (NULL, " ");
}
if (check == 0 & i == 3)
printf("\nCorrect\n");
else
printf("\nWrong\n");
}
Comments
Leave a comment