A
AMP
Willy and all
Thanks so much for all your help.
My problem was I didnt understand the function.
I had a couple "c" guys take the time to explain it.
Mike
Thanks so much for all your help.
My problem was I didnt understand the function.
I had a couple "c" guys take the time to explain it.
From there I used your example and it worked great.
Mike
|I have been trying, but there is a problem with the type conversions
| also
| sscanf(strdata[linepos], "%3x", blkout[dataframelen]);
|
| strdata[linepos] is a char Array
| %3x is "Read a Max of 3 Chars and format it as an int."
| blkout[dataframelen]); is a byte Array
|
| So to me I see:Read a max of 3 chars from strdata, format it as an int
| and store it in blkout[dataframelen](a byte) I dont know how to do
| that.
|
| The entire section of code:
| /* Transfer data in line into blkout: */
| for(linepos= 0;
| linepos < linelen-3; linepos+= 3, dataframelen++)
| {
| sscanf(&strdata[linepos], "%3x", &blkout[dataframelen]);
| /* (Max 16 bytes per line!) */
| }
|
Well, consider following sample...here I assume that the input buffer looks
like:
buffer = " ff c2 ff fe de de ba ba cc 12 25 66 9a 63 55 87";
...
byte[] ahexVal = new byte[16];
installResult = " ff c2 ff fe de de ba ba cc 12 25 66 9a 63 55 87";
for(int n = 0, m = 0; n < 48; n+=3, m++)
result = Byte.TryParse(installResult.Substring(n, 3),
NumberStyles.HexNumber, null, out ahexVal[m]);
foreach(Byte b in ahexVal)
Console.Write("{0:x}", b);
So what I'm doing is parsing the buffer, checking for a valid hex number
sequences (every third character starting from 0 with a width of 3
characters)). Every valid hex value will be stored as a byte value in an
array of bytes.
But, I would urge you to start thinking in terms of C# and the framework.
While both C# and C share some common grounds as a language, the C library
and the FCL on the other hand do not, that means that you should not try to
mimic C contructs in C#, it's a waste of time.
Also don't think you can learn both C and C# at the same time, you'll have
to make a choice, and because you are here, your choice should be C#.
Start with C# and spend most of your time with the FCL, it offers a much
richer set of API's than the C library.
Willy.