C/C++ gurus ! help ! - dStrrchr is always const char
by Orion Elenzil · in Technical Issues · 01/03/2006 (5:33 pm) · 2 replies
Hello C++/C gurus !
There are two versions of dStrrchr():
i'm think i'm having trouble getting VS7 to believe that i want the char*, not the const char*.
with the following code i get "error C2106: '=' : left operand must be l-value".
how can i elegantly get it to do what i want ?
i've tried casting dStrrchr to char* as well as casting buf to char* in the call to dStrrchr.
tia,
orion
There are two versions of dStrrchr():
char* dStrrchr(char *str, int c); const char* dStrrchr(const char *str, int c);
i'm think i'm having trouble getting VS7 to believe that i want the char*, not the const char*.
with the following code i get "error C2106: '=' : left operand must be l-value".
how can i elegantly get it to do what i want ?
char buf[128] = "blahblah.foo"; // "=" gives l-value error on left operand: dStrrchr(buf, '.') = '[[60c1fa3019d69]]'; // gives the same error: (char*)(dStrrchr((char*)pathBuf, (int)'.')) = '[[60c1fa3019d69]]'; // this works, but it's ugly: buf[dStrrchr(buf, '.') - buf] = '[[60c1fa3019d69]]'; // this also works, and isn't so ugly, but makes me feel bad about myself: char* ret; ret = dStrrchr(buf, '.'); ret = '[[60c1fa3019d69]]';
i've tried casting dStrrchr to char* as well as casting buf to char* in the call to dStrrchr.
tia,
orion
About the author
#2
thanks Joseph.
where was my mind.
interesting that my last "this also works" example compiles but is totally wrong.
edit: added in checking for NULL return as well, of course.
01/04/2006 (9:49 am)
Oh, duh.thanks Joseph.
where was my mind.
interesting that my last "this also works" example compiles but is totally wrong.
edit: added in checking for NULL return as well, of course.
Torque Owner Redacted