-
newbie problem
I have a newbie-ish problem (not that I'm a newbie :cool: )
I'm using the strcmp function for like the 1st time and i get this error:
Code:
error C2664: 'strcmp' : cannot convert parameter 2 from 'char' to 'const char *'
I'm using the following variables in the following call to strcmp():
Code:
char bo = 'b';
char must_be_str = bo;
char entered[MAX_PATH];
if(strcmp(entered, must_be_str) == 0) {
// whatever
}
Its probably becuase the first is declared as a single char and the other is declared as an array of chars of size MAX_PATH (defined somewhere else). The question is: what do I do to dodge this obstacle? I've tried this:
Code:
char bo[MAX_PATH];
bo[0] = 'b';
char must_be_str = bo;
char entered[MAX_PATH];
if(strcmp(entered, must_be_str) == 0) {
// whatever
}
but when I do this, its still doesn't work. Any ideas? BTW, the 'entered' variabled is taken from a TextField using GetDlgItemText.
Thanks :D
-
The " == " operator isn't overloaded for char's like it is for 'strings' explaining your dilemma with
Code:
if(strcmp(entered, must_be_str) == 0)
I would consider converting your char data to strings as a quick (?) fix if you want to use 'strcmp'.
(Your reference to a "TextField" brings Java to mind and Java text fields contain strings.)
:)
-
i think the problem is
char must_be_str = bo;
this should be
char must_be_str[3]="bo";
-
bo is the name of the variable which contains 'b'
-
how do I get around this const char* bussiness when I only use chars? Why did they make the fuction only use const char*s?
-
strcmp probably doesn't check single chars for comparision.
it checks only arrays
also you try strcpy() to copy bo to must_be_str and then see...
-
I don't see the problem. You are trying to compare a character, so don't use the strcmp function.
Code:
char bo = 'b';
char entered[MAX_PATH];
if(*entered == bo) {
// whatever
}
-
Yeah Monster is right.
For arrays: strcmp()
For single chars: use the == operator