if(''' == command[j])

This is a discussion on if(''' == command[j]) within the C++ Programming forums, part of the General Programming Boards category; Im trying to do something if command[j]==' however the below code doesnt work if(''' == command[j])...

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    if(''' == command[j])

    Im trying to do something if command[j]==' however the below code doesnt work

    if(''' == command[j])
    AIM: MarderIII

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    lose the quotes:

    Code:
    if (something == command[j])
    {
    ...
    }
    That what u mean?

  3. #3
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    uh i dunno everything else ive been doing has been like this:

    Code:
    if('z' == command[j])
    {
    cout<<"26";
    }
    AIM: MarderIII

  4. #4
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Posts
    80
    Code:
    if (command[j] == ' \ '')
         // do something
    Without the spaces.

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    What data types are you using char arrays or the string class?

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
       string s2[] = { "test", "testing", "tested" };
       
       for(int i=0; i < 3; i++)
          if("test" == s2[i])
             cout << "26" << endl;
          else
             cout << s2[i] << endl;
       
       return 0;
    }
    You cannot test char arrays like this. You need a 2D char array and strcmp.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Originally posted by slaveofthenet
    Code:
    if (command[j] == ' \ '')
         // do something
    Without the spaces.
    This man is correct. Disregard everyone else's replies.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help
    By mkdl750 in forum C Programming
    Replies: 45
    Last Post: 07-17-2008, 10:44 PM
  2. Separate long string into multiple arrays
    By cashmerelc in forum C Programming
    Replies: 6
    Last Post: 11-27-2007, 02:57 AM
  3. Error message in tic tac toe problem please help
    By Kross7 in forum C++ Programming
    Replies: 17
    Last Post: 04-10-2007, 02:50 PM
  4. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 01:50 AM
  5. Need help with Tic Tac Toe
    By Zerostatic in forum C++ Programming
    Replies: 19
    Last Post: 07-19-2002, 08:20 PM

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