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

char* term1;
term1 = "f(x)";

//i really have a loop here... 

if ( term1[1] == "(" )   <------ Error here
{
  //do stuff...
}

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!

Recommended Answers

All 3 Replies

double quotes mean a null-terminated string, single quotes is a single character. Replace the double quotes in the if statement to single quotes.

if ( term1[1] == '(' )

Ha and it was easy as that :)

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

Thanks a million and for the quick response!
:cheesy:

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.