Compare Char[] to ""

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2005
Posts: 3
Reputation: superservo15 is an unknown quantity at this point 
Solved Threads: 0
superservo15 superservo15 is offline Offline
Newbie Poster

Compare Char[] to ""

 
0
  #1
Sep 29th, 2005
I'm having type problems... if anyone could help that'd be great. Also, I haven't coded in c++ for 2 years.. very rusty

Ok, I have the following dynamic char array and code

  1. char* term1;
  2. term1 = "f(x)";
  3.  
  4. //i really have a loop here...
  5.  
  6. if ( term1[1] == "(" ) <------ Error here
  7. {
  8. //do stuff...
  9. }

Now, the error I get says I cant compare an int to a char... it appears that term1[1] is changing from a char to a small int.

What can I do to make this comparison work?
Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,500
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Compare Char[] to ""

 
0
  #2
Sep 29th, 2005
double quotes mean a null-terminated string, single quotes is a single character. Replace the double quotes in the if statement to single quotes.
  1. if ( term1[1] == '(' )
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 3
Reputation: superservo15 is an unknown quantity at this point 
Solved Threads: 0
superservo15 superservo15 is offline Offline
Newbie Poster

Re: Compare Char[] to ""

 
0
  #3
Sep 29th, 2005
Ha and it was easy as that

soooo used to vb... i'm regressing.. haha

Thanks a million and for the quick response!
:cheesy:
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 6
Reputation: ITgeneration is an unknown quantity at this point 
Solved Threads: 0
ITgeneration ITgeneration is offline Offline
Newbie Poster

Re: Compare Char[] to ""

 
0
  #4
Sep 30th, 2005
AOA
note that every c and c++ Singly character in singal qutaion markes
just like 'a' , '(' and any other
and a string is Double Qutaion markes just like "me" , "String" ,"this is a example" ok
:eek: ALLAH HAFIZ
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC