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 CCS Technical Support

How to make a Long String from a Buffer(array)

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



Joined: 07 Oct 2003
Posts: 3
Location: North Wales. UK

View user's profile Send private message

How to make a Long String from a Buffer(array)
PostPosted: Thu Dec 01, 2011 4:19 pm     Reply with quote

I can read the serial number using the example from ex_touch.c and display it on lcd no problem.

I am however, having problems in trying to make a long string from an array.

I am readng the serial number from an iButton (DS1990a). I get the following;

Code:

Array  [0]  [1]   [2]  [3]   [4]  [5]   [6]  [7]
buffer  01   2D    C5   B8    00   00    00   BC       

What I want to do is to put this into 1 long string i.e. "012DC5B8000000BC". Thinking this would be an easy way to check whether it was valid against stored serial numbers using strcmp.

I am trying the following but only get '0's in cString1.

Code:

   BYTE buffer[8];
   Char cString [9];
   Char cString1 [9];

        for(i=0;i<8;++i)                    // Set i between 0 & 8
         {
          buffer[i]=touch_read_byte();     // Read 8 bytes of button data * Works *
          sprintf(cString,"%c",buffer[i]);   // Convert to string
          strcat(cString1,cString);            // Concatenate s2 onto s1
         }


Any pointers where i'm going wrong or even simpler methods

Using PIC16F877A
compiler version 4.110.

Thanks in advance
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 01, 2011 5:25 pm     Reply with quote

If you want to convert binary to ascii hex. Use "%x", not "%c".
This is in the manual. See the printf section.
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