View Single Post
Re: strings aaaaaaaaaaarghhhhhhhhh
Old
  (#5)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: strings aaaaaaaaaaarghhhhhhhhh - 08-04-2004

You're tired, Stefan... Get more sleep
Quote:
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]);
...might work better if you were doing
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 !!!



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote