On Fri, 19 May 2000, Zednanreh Solo wrote: > I'm having a problem with ascii pfiles that hasn't been brought up yet. I > fixed up diskio.c with no problems. I'm usinv MSVC++6 with Oasis 2.x and bpl > 17. Heres the only error: > > db.c > c:\circle30bpl17\src\db.c(2202) : error C2106: '=' : left operand must be > l-value > > case 'N': > if(!strcmp(tag, "Name")) > // GET_NAME(ch) == line; > // strcpy(GET_NAME(ch), line); > GET_NAME(ch) = str_dup(line); // <------------ > break; The line you point to is fine. However, this code demonstrates a fundamental misunderstanding of c programming, aside from memory usage and others. As a learning experience, lets go though it step by step. 1 case 'N': 2 if(!strcmp(tag, "Name")) 3 GET_NAME(ch) == line; 4 strcpy(GET_NAME(ch), line); 5 GET_NAME(ch) = str_dup(line); 6 break; 1. This line is fine; it's correctly closed @ line 6. 2. This line is also correct, strcmp returns 0 if the match is equal - so checking for !strcmp() means it will show up as true if it matches "Name" - but lets look at the rest of this; you've used indenting as if it is what delimits an 'if' block. lines 3-5, you have indented them - now.. what really happens instead of having those in your one brace, what you have is: if(!strcmp(tag,"Name")) { GET_NAME(ch) == line; } strcpy(GET_NAME(ch),line); GET_NAME(ch)=str_dup(line); Those bottom two lines will be executed for EVERY match to the 'N' case - ie, every field that has the first letter of 'N'. Bad move chum. Now, lets take that first line - 3 - the one that actually is in the 'if' block. It's "GET_NAME(ch) == line;". That's it. This line doesn't do anything. It will most likely evaluate to 0. You just performed an eval; this is a test.. 1 or 0. Usually, these are used in 'if' statments. Yours is not. It does nothing. Okay, now, lets take line 4. It actually could be correct. Of course, it isn't. See, strcpy copies a string from a source to a destination. It does not however (like str_dup/strdup), allocate memory. So, this will give you odd errors as you follow the dangling pointer and write into never-neverland. No one could really say what it does exactly. But it's probably bad if you didn't intend it to deliberately mess up things. Good news. Line 5 is kosher. It should probably be the one (and only) thing within the if braces. It's also what you want. PjD +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/10/01 PDT