CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to convert a byte array to a string....

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
oladawg
Guest







how to convert a byte array to a string....
PostPosted: Mon Mar 21, 2005 11:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2005 1:59 am     Reply with quote

Why not comparing the byte direct using a switch statement ?

Will be the fastest solution and is easy to program

Andreas
Ttelmah
Guest







PostPosted: Tue Mar 22, 2005 5:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2005 5:35 am     Reply with quote

why strcmp and not memcmp?
Ttelmah
Guest







PostPosted: Tue Mar 22, 2005 8:22 am     Reply with quote

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







PostPosted: Tue Mar 22, 2005 8:24 am     Reply with quote

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....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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