|
|
View previous topic :: View next topic |
Author |
Message |
oladawg Guest
|
how to convert a byte array to a string.... |
Posted: Mon Mar 21, 2005 11:57 pm |
|
|
Hey guys i'm trying to convert some information from ibuttons, which is giving in bytes to a string so I can make a strcmp to see if i perform a function or not....
The question is does anybody know how to convert a byte array to a string....
Any help would be most appreciated.....
O |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Tue Mar 22, 2005 1:59 am |
|
|
Why not comparing the byte direct using a switch statement ?
Will be the fastest solution and is easy to program
Andreas |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 22, 2005 5:24 am |
|
|
In one sense, a byte array, already is a string.
If (for instance), you have:
byte demo[8] = {0x20,0x48,0x65,0x6c,0x6c,0x6f,0x20,0};
Then print("%s",demo), will print ' Hello '.
The only special feature of a 'string', is that it must have a null terminator, and as such, a null must not appear anywhere else in it.
However the code for strcmp, is in the string.h include file, and doing a version to allow zero to exist, and just use a size (like strncmp, but ignoring the terminator), will allow byte arrays to be compared, without having to fiddle around, or worry about the terminator characters, ad is probably easier.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Mar 22, 2005 5:35 am |
|
|
why strcmp and not memcmp? |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 22, 2005 8:22 am |
|
|
Will the same rules apply if i'm trying to move:
byte demo[8] into a char string[]?????
Or is there some special function I have to perform??? |
|
|
oladawg Guest
|
|
Posted: Tue Mar 22, 2005 8:24 am |
|
|
Sorry Ttelmah, i was going to quote you and i went about it the wrong way and I put your name down as if you were asking the previous question..... Hey that's a good way to get somebody in trouble.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|