943,685 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 34648
  • C++ RSS
Sep 29th, 2005
0

Compare Char[] to ""

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
superservo15 is offline Offline
3 posts
since Sep 2005
Sep 29th, 2005
0

Re: Compare Char[] to ""

double quotes mean a null-terminated string, single quotes is a single character. Replace the double quotes in the if statement to single quotes.
C++ Syntax (Toggle Plain Text)
  1. if ( term1[1] == '(' )
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005
Sep 29th, 2005
0

Re: Compare Char[] to ""

Ha and it was easy as that

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

Thanks a million and for the quick response!
:cheesy:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
superservo15 is offline Offline
3 posts
since Sep 2005
Sep 30th, 2005
0

Re: Compare Char[] to ""

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ITgeneration is offline Offline
6 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with c++ program
Next Thread in C++ Forum Timeline: Making a MUD





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC