If then Else statement help

This is a discussion on If then Else statement help within the C++ Programming forums, part of the General Programming Boards category; if (condition) statement1 else statement2 How do I say, if what the user typed in equals the string that I ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19

    If then Else statement help

    if (condition) statement1 else statement2

    How do I say, if what the user typed in equals the string that I want it to equal then execute the function.

    Thanks,

    -Nos

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Use strcmp() to compare strings.

    Code:
     
    char a[] = "nosfearatu" ; 
    char b[] = "nesfearatu" ; 
    
    if ( strcmp( a, b ) == 0)  match_func() ; // true 
    else nomatch_func() ;
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. issue with switch statement
    By bluetxxth in forum C Programming
    Replies: 14
    Last Post: 02-24-2010, 10:01 AM
  2. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 06:19 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM

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