How do I use the char & true function?

This is a discussion on How do I use the char & true function? within the C++ Programming forums, part of the General Programming Boards category; ok I've done a program with switch code, the thing is that I want to be able to let the ...

  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
    ...
    ... is offline
    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
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    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, 09:28 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  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, 12:57 PM

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