Answer to Question #325345 in C for ndars

Question #325345

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.

1
Expert's answer
2022-04-07T13:13:43-0400
#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");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS