How to create string

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create string

938 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sat May 25 07:38:17 MST 2013
Hi all,

Could someone please advise on how to create a string in LPCXPRESSO? I measures the temperature using a temperature sensor and I would like to insert this value into the text which appears on the display. How do I do that?
0 Kudos
Reply
10 Replies

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Sat May 25 18:14:45 MST 2013

Quote: masterboy
Is there a way to join 2 strings? For example:



Yes - strcat.

Refer to the classic book "The C Programming Language" by Kernighan and Ritchie if the libraries you are using do not include basic string manipulation functions like this.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 25 11:43:50 MST 2013

Quote: masterboy
Really? There is no other option? I know functions itoa / uitoa, but how do I join multiple variables of type 'char'?:(



That are simple bytes, you can use memcopy or, if you are worried about code size, just write your own loop to add this bytes.


Quote: masterboy
sprintf is crazy function that inflates the code of approx. 11 kilobytes :(


Perhaps you should read http://www.support.code-red-tech.com/CodeRedWiki/UsingPrintf?highlight=%28CR\_INTEGER%29 to reduce that size.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sat May 25 11:11:53 MST 2013
Really? There is no other option? I know functions itoa / uitoa, but how do I join multiple variables of type 'char'?
sprintf is crazy function that inflates the code of approx. 11 kilobytes :(
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 25 09:40:44 MST 2013

Quote: masterboy
Is there a way to join 2 strings?


Yes, 'sprintf'.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 25 09:31:47 MST 2013

Quote: masterboy
This is the only option?


No, there's also itoa.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sat May 25 09:31:23 MST 2013
Is there a way to join 2 strings? For example:

char str1[3] = 'XYZ';
char str2[5] = 'test1';

char str[8] = str1 + str2;
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sat May 25 08:59:20 MST 2013
This is the only option?
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 25 08:13:16 MST 2013
I would suggest to use the classical 'sprintf'.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by masterboy on Sat May 25 07:55:25 MST 2013
I mean, a string, such as:
I have value of temperature
uint8_t t = 23;


and I would like to create this string that I save to a variable:

"Temperature is 23 degrees"

And this text I can send to LCD display (2x 16 chars). I know that in the classical C, the function uses sprinf.
0 Kudos
Reply

849 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat May 25 07:50:40 MST 2013

Quote: masterboy
... I would like to insert this value into the text which appears on the display.


:confused:

Are we talking about IDE console?
0 Kudos
Reply