Thread: if's using char's

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    10

    Question if's using char's

    Im trying to write some code to make it if somone enters a word (no just a letter) then it will do something else. Cant seem to figure it out.

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post use strcmp()

    if(! strcmp(mystring, "string #2"))
    {
    // char array 'mystring' == 'string #2'
    // Do This
    }
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    could you please explane

    Could you please .. explain .. more ...

    is that a choices.. or .. just one word... .

    if this word1 then PL:APALAL
    IF this is word2 then PALALALALALLA
    etc....

    you can use switch loop for that..
    C++
    The best

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Code:
    char inputBuffer[32];
    cin.getline(inputBuffer, sizeof(inputBuffer));
    
    int length = strlen(inputBuffer);
    
    switch(length)
    {
       case 0:
          {
             // no text
             break;
          }
       case 1:
          {
             // only one character
             break;
          }
       default:
          {
             // more than one character
             break;
          }
    }
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    LOL

    I think I know what you mean.

    Would you like to contiue?
    (Y/N):

    If you mean like that, to see if they typed a Y or N it goes like this
    Code:
    char ans;
    cout<<"(Y/N)";
    cin>>ans;
        if(ans == 'Y' || ans == 'y'){
             //then do all this
         }
        else{
             // do this
        }
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while condition question..
    By transgalactic2 in forum C Programming
    Replies: 3
    Last Post: 04-04-2009, 04:49 PM
  2. Counting how many chars in a string
    By tigs in forum C Programming
    Replies: 4
    Last Post: 08-05-2002, 12:25 AM
  3. really got stuck with unsigned chars
    By Abdi in forum C Programming
    Replies: 7
    Last Post: 06-11-2002, 12:47 PM
  4. move chars position
    By SpuRky in forum C Programming
    Replies: 3
    Last Post: 06-09-2002, 02:59 AM
  5. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM