1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why is there a letter 'i' after strcmp?

Discussion in 'C' started by Player, Mar 10, 2009.

  1. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    Hi all.

    I cannot see why there is a letter 'i' after the strcmp function? The program runs fine without it and it doesn't explain in my book why it's there. It's the first time it's used and i have looked at other string functions and can't seem to be able to see a reason behind it. Here's my source code. I have made a comment where the problem lies.

    Thanks in advance.
    Code:
    #include<string.h>
    #include<stdio.h>
    
    int main()
    {
        char dwarf[7][2][8]={
             "bashful","?",
             "doc","?",
             "dopey","?",
             "grumpy","?",
             "happy","?",
             "sneezy","?",
             "sleepy"};
        char input[64];
        int named=0;
        int x;
        
        puts("See if you can name the seven dwarfs:");
        
        while(named<7)
        {
            if(named==1)
                printf("\nSo far you have named %d dwarf.\n",named);
            else
                printf("\nSo far you have named %d dwarfs.\n",named);
            printf("Enter a name:");
            gets(input);
            
        /*check for no input*/
            if(strcmp(input,"")==0)//no input, end
            break;
            
            for(x=0;x<7;x++)
            {
                if(strcmpi(input,dwarf[x][0])==0)/*WHY IS THERE A LETTER "I" AFTER STRCMP?*/
                {
                    if(dwarf[x][1][0]=='!')
                        printf("You already named that dwarf!\n");
                    else
                    {
                        printf("Yes! %s is right.\n",input);
                        named++;
                        dwarf[x][1][0]='!';
                    }
                }
            }
        }
        return(0);
    }
     
    Last edited by a moderator: Mar 11, 2009
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    The comparison is not case-sensitive.
     
  3. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    The comparison is case sensitive. "strcmp" is case sensitive and "strcasecmp" isn't case sensitive (according to my book, could my book be wrong?). This still doesn't explain why the letter 'i' is inputted after strcmp. :crazy:
     
    Last edited: Mar 11, 2009
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
  5. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Shabbir. I was getting confused because i thought "strcasecmp" was the only function that wasn't case sensitive. I didn't realise that strcmpi was the same thing. Thanks for your help in this :)
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    The pleasure is all mine
     

Share This Page