C2106, how to fix it...
hey all,
I am trying to compile some code I just wrote, and my MSVC is reporting:
error C2106: '=' : left operand must be l-value
I looked up the C2106 description at msdn, and it doesn't really tell me much that the report doesn't. here is the code:
p = PathFindFileName(szListData[i][0]);
pfile->name = p;
p is declared:
char *p = "";
and name is declared:
char name[_MAX_FNAME];
could anyone please tell me what I am doing wrong here, and what I can do to fix it? I am still somewhat new with pointers, any help would be greatly appreciated.
thank you in advance! :)
[686 byte] By [
sleak] at [2007-11-20 2:12:38]

# 1 Re: C2106, how to fix it...
The reason for the compiler error is that p is a pointer to an array of characters, but name is an array of characters.
Instead of
pfile->name = p;
try using
strcpy(pfile->name,p);
http://www.cplusplus.com/ref/cstring/strcpy.html
:)
# 2 Re: C2106, how to fix it...
thanks Zaccheus, but I had tried that prior to posting here. it will compile fine like that, but when I run it, Windows throws up an error message saying that the application needs to be closed.
pfile->name should generate a pointer to the first element of name. I believe PathFindFileName is supposed to return a pointer to the first element of the file name. so I don't see why my MSVC is reporting the C2106.
tbh I had tried almost everything. including declaring name as a pointer as apposed to an array, getting the string length (using strlen) of p plus 1 (for the null), and using malloc to allocate name before I assigned p to it. but that also caused the application needs to be closed error message.
sleak at 2007-11-9 13:26:26 >

# 3 Re: C2106, how to fix it...
If p points to a null-terminated string which has up to _MAX_FNAME characters in it, then strcpy should work.
Can you give us more information?
# 4 Re: C2106, how to fix it...
How is this pfile struct initialized? If you have not already, you must allocate memory for it, and make sure to free it when you are done.
# 5 Re: C2106, how to fix it...
This may or may not fix your problem because I can't see the size of _MAX_FNAME -- basically, the PathFindFileName() function expects a string of up to MAX_PATH long, not _MAX_FNAME.
Greg Dolley