Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC16f877a joining two strings in mikroc help

Status
Not open for further replies.

Ernest Clyde Chua

Newbie level 6
Newbie level 6
Joined
Jul 29, 2014
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
69
hi im new to c and mikroc,
im having troubles with joining two strings, can some one help\teach me how it is done?

heres my code:
Code:
d=12;
IntToStr(d, dtemp);
txt=strcat("0",dtemp);
LCD_Out(2, 1,txt );
i cant compile the code what is wrong in my code?
also im trying to print it on the lcd like this:012

- - - Updated - - -

i change it in to this

Code:
d=12;
m=0
IntToStr(d, dtemp);
IntToStr(m, mtemp);

strcat(dtemp, mtemp);
            LCD_Out(2, 1, dtemp);
it displays wierd symbols
 
Last edited:

if you look at the specification of strcat()
https://www.cplusplus.com/reference/cstring/strcat/

i.e
Code:
char * strcat ( char * destination, const char * source );
you will see the first parameter is the destination and the source is concatenated onto it

in your code
Code:
txt=strcat("0",dtemp);
the first parameter "0" is a string constant and will either give a compiler error or a run time such as a segmentation fault
make the destination a char array and it will work, e.g.
Code:
char txt[50]="0";
strcat(txt,dtemp);
 

i found a new solution but still something is wrong, it has spaces in between them
how can i remove these spaces?

heres the code

Code:
d=12;
m=0;
IntToStr(d, dtemp);
IntToStr(m, mtemp);

txt[12]=strcat(mtemp,dtemp); 
            LCD_Out(2, 1, txt[12]);
 

Use the Ltrim function.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
char mtemp[7+7]; // long enough to accomodate two 7-char arrays
char dtemp[7];
 
// .....
 
d = 12; // any signed (!) integer number 
m = 0;  // ditto  
 
IntToStr(d, dtemp);
IntToStr(m, mtemp);
LCD_Out(2, 1, strcat(Ltrim(mtemp), Ltrim(dtemp));

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top