Coder's Guild Mailing List

Re: plz hlp me

Posted by Hal Bonnin on 2000-02-03

>I am running VC++ 6.0, and the line I would like to read in looks like
>00000000:   00700012  000071111 080A0400  00000008
>sscanf(strOneLine,"%x  %x %x %x %x\n", &Data.Reg[i], &Data.Reg[i+0x08],
>&Data.Reg[i+0x0F], etc, etc, )

sscanf(strOneLine,"%x:  %x %x %x %x\n", &Data.Reg[i], &Data.Reg[i+0x08],
&Data.Reg[i+0x0F], etc, etc, )

will work. if you put in the static characters like i did for you, it will
read them and ignore them.

my favorate method for reading in a unknown variable is with delimiters like
this

DATA:
TEST|002334|LEFT|CENTER|14.665|TRUE|

call
char DATA[6][500];
// clear data so you can tell if a null is recieved
strcpy(DATA[0],"");strcpy(DATA[1],"");
strcpy(DATA[2],"");strcpy(DATA[3],"");
strcpy(DATA[4],"");strcpy(DATA[5],"");
sscanf(strOneLine,"%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|", &DATA[0],&DATA[1],
    &DATA[2]&DATA[3]&DATA[4]&DATA[5]);
Data.Reg[i]=atoi(DATA[0]);

NOTE: you have to have something between the delimiters, even if just a
space else the entire remaining data will be corupt.
NOTE data recieved in my example must be less then 500 characters in length
else corruption.
NOTE this method allows for multiplatform use because 16bit vs 32 bit will
gather different numbers using the automatic method. my method allows for a
check before assigning the data.

most common delimiters are the  |   ","   ~

i only use sscanf in my programs. and i am using MSVC++ 6.0 right now. it is
very stable and reliable if you know the rules. (rules about pointers,
redirection,memory allocation, etc.)



Sponsored by Wrox Press - www.wrox.com. Programmer to Programmer (TM)
To signoff send a mail to listserver@xxxx.xx.xx with 
  "signoff tcg" in the body of your message.