Thread: How do I use the char & true function?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    11

    How do I use the char & true function?

    ok I've done a program with switch code, the thing is that I want to be able to let the user type "YES" or "NO" in one of the options so that the program should re-start or whatever.. do you know what i mean?

    Thanks,

  2. #2
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    Get the command as a string
    char stringname[4];
    cin >> stringname;
    then compare it (case-sensitive)
    Code:
    if (srcmp(stringname,"YES")==0) {
      cout << "stringname is YES" << endl;
    }

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >if (srcmp(stringname,"YES")==0) {
    Small typo:
    if (strcmp(stringname,"YES")==0) {

    Or you can use C++ style strings:
    Code:
    #include <string>
    using namespace std;
    int main(void)
    {
       string stringname;
       cin >> stringname;
    
       if (stringname == "YES")
          cout << "stringname is YES" << endl;
    
       return 0;
    }

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    you can use stricmp() for case insensitive comparisons.
    I came up with a cool phrase to put down here, but i forgot it...

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I thought it was strcmpi()
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    stricmp() and strcmpi() both work.
    I believe neither is an ANSI standard function?
    Someone correct me if I'm wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM