![]() |
strings aaaaaaaaaaarghhhhhhhhh
I am getting nuts of this! Especially because i do the same thing twice, and one works one does not.
Okay, let me explain. I have a string, 80 characters, declared as: Code:
class cChatEngine char sentence[80]; this one gets initialized: sentence[0] = '\0'; in init(); So far so good, it gets filled in when a user says something (intercepting SayText, this also works okay (btw, code partially just copied from podbot source as i wont invent the wheel twice): Code:
void BotClient_CS_SayText(void *p, int bot_index) Okay, now, the set_sentence function: Code:
void cChatEngine::set_sentence(char csender[30], char csentence[80]) here is the problem!!!: as soon as i try to read ONE character from the line, it does not work, ie: Code:
sprintf(msg, "%s", sentence[1]); Code:
sprintf(msg, "%s", &sentence[1]); Now here is a little code that should check the sentence PER CHARACTER, and then copy characters into words. I know it should work, because i have a function working almost the same way (it reads out the character the same way) and i do not have trouble there. Code:
// Scan the message so we know in what block we should be to reply: - does anybody know what is wrong? - does anybody know why this function does work, but the above not?: Code:
void |
Re: strings aaaaaaaaaaarghhhhhhhhh
Just scanned your code and found this typo where you seem to have located your problem:
if (sentence[c] == ' '); { ... the extra ; might be a nuisance 8o :D I didn't check the code seriously but if all you do is string copying you could just use strcpy() instead of the combo sprintf(sTo,"%s",sFrom). Hope this helps. I'm going to bed now too. Goodnight :) |
Re: strings aaaaaaaaaaarghhhhhhhhh
Now I am not a geek at C++ but it looks like you declared "word[c]" to be '\0' and your problem comes when "strlen(word)" is less than or equal to "0" which is NULL right?. Just trying to help but dont think that I am:D
MusicMan |
Re: strings aaaaaaaaaaarghhhhhhhhh
Hm, you are declared word[c] initialized it to be zero-string, never changed its value ... it always be with zero length :) That is why you are gettin tons of messages "this is not a good word"
|
Re: strings aaaaaaaaaaarghhhhhhhhh
You're tired, Stefan... Get more sleep :)
Quote:
sprintf (msg, "%c", sentence[1]); instead, hmmm ? :) If you do sprintf (msg, "%s", sentence[1]); and your "sentence" is something like "Hello my name is Stefan\n", you ask printf() to print out the STRING ("%s") that starts at the ADDRESS described by the 2nd element in the sentence[] array, that is, sentence[1] being 'ello' (since an int does 4 bytes), printf() will go and look for a string at address 0x656c6c7f (which is "ello" in hex) in memory, which is probably not what you want it to do !!! |
Re: strings aaaaaaaaaaarghhhhhhhhh
Kickbot, i love ya. PMB you too!
The ; already caused tons of problems. I removed the ; and it already gives me only a few "not a good word" thingies. PMB, the character printing now works too so it does not crash. phew. Okay, now i know the function grabs words okay, it only does not recognize them yet. but i think i can manage from here. If not i'll let ya know :) |
Re: strings aaaaaaaaaaarghhhhhhhhh
always use char pointers (char*) in function parameters, makes it easier for me :P
|
Re: strings aaaaaaaaaaarghhhhhhhhh
In writing its easier, but i'd rather know what i allocate instead of using pointers and 'can be any size' chars.
|
Re: strings aaaaaaaaaaarghhhhhhhhh
Quote:
|
Re: strings aaaaaaaaaaarghhhhhhhhh
as long as you don't wanna change msg any more ...
|
Re: strings aaaaaaaaaaarghhhhhhhhh
If you are into C++ programming, then why not make use of the standard string class? It works nicely and is far simpler than using character arrays.
|
Re: strings aaaaaaaaaaarghhhhhhhhh
Quote:
|
Re: strings aaaaaaaaaaarghhhhhhhhh
oops, sorry, I was thinking in terms of pointers :)
and stefan : don't be so stupid to implement some kind of 1337 chat generator in your chat system ;) I still get mails of users telling me about this "bug" :D *g* but I leave it there ... somehow it looks cool :) |
All times are GMT +2. The time now is 16:22. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.