-3

The code below is written in C. What the code does is to show a name or any word that is typed by a user. But when I compiled and run the code, typing both a number or a name, it displayed "What you have typed is neither a name nor a number." Let me know what is wrong with the code.

#include <stdio.h>

typedef char String[1014];

int main(void)
{
    String yourName;
    printf("Type your name\n");
    scanf("%s", yourName);
        if ((yourName >= "a" && yourName <= "z") || (yourName >= "A" && yourName <= "Z"))
            printf("Hello Mr.%s\n", yourName);
        else if ((yourName >= "0" && yourName <= "9"))
            printf("Type your name, not a number!");
        else
            printf("What you have typed is nither a name nor a number.\n");
    return 0;


}
DYZ
  • 51,549
  • 10
  • 60
  • 87
John2
  • 149
  • 1
  • 1
  • 5
  • 1
    `yourName >= "a"` is meaningless. You must use `strcmp` to compare strings. – DYZ Dec 09 '18 at 06:51
  • 1
    The dupe addresses what you arre doing. However, that's not what you need. Make yourself clear **what** a name and a number are (i.e. what they may consist of semantically) and check for this. A comparison won't work here. – too honest for this site Dec 09 '18 at 07:01

1 Answers1

-1

You are comparing an alphabet with string which is why condition is never net.

This might help you

C programming: How to check whether the input string contains combination of uppercase and lowercase