Please help me resolve this. What did I do wrong?
Code:char *findC (char const *source, char const *obj) { int i; for (i = 0; i < 6; i++) { if (*(source + i) == *obj) { return &(source + i); //l-value error here } }; return NULL; }
Please help me resolve this. What did I do wrong?
Code:char *findC (char const *source, char const *obj) { int i; for (i = 0; i < 6; i++) { if (*(source + i) == *obj) { return &(source + i); //l-value error here } }; return NULL; }
You can't take the address of an expression, only of a variable. Even if you could, you'd be returning a char** instead of a char*. Get rid of the & and you should be fine.
I got this error when the & is removed:
error C2440: 'return' : cannot convert from 'const char *' to 'char *'|
Right. Since source is a const char *, and the return value is based on that, you need to return a const char *.
How do I do that? It keeps giving me a syntax error. Do I need to introduce a new const pointer?
EDIT: Nope, doesn't work. I have no idea what to do.
The return value of your function is "char *". Change it to "const char *".
Many thanks!