0

I have a code:

int main()
{
    printf("to exit the program type \"exit\":");
    char s[40];
    scanf("%s",s);
    if(strcmp(s,"exit")==0)
    {
        exit(0);
    }
    else
    {
        int n;
        printf("wrong");
    }
    return 0;
}

I want to when I enter "ExIt" it works. how can i change that?

walid barakat
  • 455
  • 1
  • 6
  • 17
Pouria
  • 39
  • 8

2 Answers2

1

you can use tolower() in C, but it works for char, so maybe you need to itterate over s string and putting every char to lower case.

walid barakat
  • 455
  • 1
  • 6
  • 17
  • Without explaining the shortcomings this is *dangerous advice* because it fails for non-English alphabet languages. In general you **should not** implement case-insensitive comparison by converting the characters. Use a proper case-insensitive compare instead. – Konrad Rudolph Jul 15 '20 at 08:03
  • oh, you're right, i just thought the mate works on a simple code and maybe just a hint will be useful, but i hope he sees your comment – walid barakat Jul 15 '20 at 08:14
-1

use stricmp instead of strcmp.

More letters to hit 30

LoztInSpace
  • 5,584
  • 1
  • 15
  • 27