problem with if and character

This is a discussion on problem with if and character within the C Programming forums, part of the General Programming Boards category; // 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\ ...

  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
    32,851
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 07:12 PM
  2. Character problem
    By popescuradhoo in forum C Programming
    Replies: 3
    Last Post: 05-09-2008, 01:26 PM
  3. Problem in reading Character
    By Bargi in forum C Programming
    Replies: 5
    Last Post: 04-11-2008, 12:40 AM
  4. Character problem!!
    By cBegginer in forum C Programming
    Replies: 3
    Last Post: 09-03-2005, 12:51 AM
  5. Character pointer problem.
    By kiss_psycho in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 02:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21