Thread: problem with if and character

  1. #1
    Registered User
    Join Date
    Aug 2011
    Location
    Sérres, Greece, Greece
    Posts
    17

    Exclamation problem with if and character

    // code\\


    printf("\nchoose your league:");
    scanf("%s",&league);

    if (league=='nba')
    printf("you have choosen nba");
    else if (league=='euro')
    printf("you have choosen euroliga");

    //code\\

    my program stops after scanf,"IF" doesn't work
    i tried after scanf to print what was given from the keyboard and i worked just fineso the problem must be in the "IF" part of the program,I would be glad if you could help me anyway thxfor your time

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use strcmp() and double quotes to compare strings in C.

    As in
    Code:
    if ( strcmp(this,"that") == 0 ) {
    }

    > // code\\
    It's [code][/code]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Location
    Sérres, Greece, Greece
    Posts
    17
    thx mate for the solution-explanation and for the tip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character problem
    By Guru_ in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2009, 06:12 PM
  2. Character problem
    By popescuradhoo in forum C Programming
    Replies: 3
    Last Post: 05-09-2008, 12:26 PM
  3. Problem in reading Character
    By Bargi in forum C Programming
    Replies: 5
    Last Post: 04-10-2008, 11:40 PM
  4. Character problem!!
    By cBegginer in forum C Programming
    Replies: 3
    Last Post: 09-02-2005, 11:51 PM
  5. Character pointer problem.
    By kiss_psycho in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 02:49 AM