Hey, mode code is glitched up. If you "get <item>" it will say it's not there. When the command is being tested, it get's altered. I don't know what's doing it. Take a look at my code (VC6). I'm really in desperate need!
Hey, mode code is glitched up. If you "get <item>" it will say it's not there. When the command is being tested, it get's altered. I don't know what's doing it. Take a look at my code (VC6). I'm really in desperate need!
I don't download attachments just to answer a question. Try posting the smallest possible program that exhibits your problem along with the input you're using, the output you expect, and the output you are actually getting. Help us to help you more easily and you will get a higher quality answer, much faster.
My best code is written with the delete key.
the problem is, I don't know what the problem is. It's a rather large application also... It would be next to impossible to post just the code that's causing the problem.. because I don't know what it is! But heres the smallest code possible that's directly causing it.CommandTest() tests to see if two things are the same, basicallyCode:if(commandTest("get", input) || commandTest("take", input)) { input = splitString(input); bool take= false; for(int i=0;i < 5;i++) { if(!area.curArea[player1.curX][player1.curY].itemsIR[i]) continue; if(commandTest(area.curArea[player1.curX][player1.curY].itemsIR[i]->pName, input, false)) { if(area.curArea[player1.curX][player1.curY].itemsIR[i]->canTake == false) { cout << "You can't take that."; take = true; break; } give((*area.curArea[player1.curX][player1.curY].itemsIR[i])); take = true; area.curArea[player1.curX][player1.curY].itemsIR[i] = 0; cout << "You took it."; break; } } if(take == false) cout << "It's not here."; continue; }
Right before I call the commandTest, the input will change from "blue" to "blue~@" and it throws everything off. And then, it will change to something totally bogus like "|p4" for no apparent reason.
I would wager that the corruption is somewhere in splitString (most likely), or in commandTest. If it's even caused here.
>It would be next to impossible to post just the code that's causing the problem.
That would be the whole point of writing a smaller application that exhibits the problem. You isolate it more easily by removing the fluff. Most of the time you can solve your own problems that way.
My best code is written with the delete key.
Post the splitString function. I'm betting that is where the problem lies. From the looks of it, commandTest logically shouldn't change anything, so I would assume (hope) that if this is the case, your strings are passed in some const manner (e.g. by const reference).
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
and command test....Code:char* splitString(char string[]) { const int len = sizeof(string)/sizeof(string[0]) + 1; char buffer[len] = {0}; int i = 0; for(;string[i] != ' '; i++); i++; int j = 0; for(;string[i] != 0;j++) { if(string[i] > 40 && string[i] < 91) { buffer[j] = string[i] + 32; continue; } buffer[j] = string[i]; i++; } buffer[++j] = '\0'; string = buffer; return string; }
Code:int commandTest(char commandName[], const char* const input, int i, bool stopSpace) { int j = 0; // CommandName counter // If its empty, return 0 if(input[0] == '\0') return 0; // If there are spaces, skip them until you get to a word for(;;) { if(input[i] == ' ') i++; else break; } // The test for(;;i++,j++) { // Is is the end or a space? if(input[i] == '\0') // Its the same return 1; if(input[i] == ' ' && stopSpace) return 1; // Is it the same letter? if(input[i] == commandName[j]) // Keep going continue; // Is it different? if(input[i] != commandName[j]){ // Its not it return 0; } } }
I noticed where the corruption takes place. When I pass down input to commandTest, before any code in the commanTest takes place, it changes "blue" to "blue- . @". And next, the first line of code (int j = 0 will make it 3 weird sybols. Something like a d with a line, a tongue and a bar. This is really weird.
The other uses of commandTest work fine. Equip, dequip, buy, sell. Werd.
> const int len = sizeof(string)/sizeof(string[0]) + 1;
This should be:
const int len = strlen(string) + 1;
> buffer[++j] = '\0';
And here:
buffer[j] = '\0';
> string = buffer;
And this:
strcpy( string,buffer );
Or alternately you could make buffer static.
I did all that; and the fact that the buffer wasnt static was one of the problems.. But the other problem... Now, when I pass down the itemName to commandTest, it will pass down a 0, even though the value is true.
Code:int commandTest(char commandName[], const char* const input, int i, bool stopSpace) { int j = 0; // CommandName counter // If its empty, return 0 if(input[0] == '\0') return 0; // If there are spaces, skip them until you get to a word for(;;) { if(input[i] == ' ') i++; else break; } // The test for(;;i++,j++) { // Is is the end or a space? if(commandName[j] == '\0') // Its the same return 1; if(input[i] == ' ' && stopSpace) return 1; if(input[i] != commandName[j]){ // Its not it return 0; } } }
Don't worry about it now, I took code from an old backup and it works now. Thanks