|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Problem with strcat |
Posted: Fri Sep 18, 2009 5:45 pm |
|
|
Reading velocity from GPS string and sending to hyperterminal, which works fine. Now wish to add "km/h" to end of string. Have tried strcat and all sorts of garbage coming out now. Any help appreciated.
Code: | #include <16f716.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2, parity=N, bits=8, ERRORS)
#include <string.h>
char z, temp[20], temp2[20];
int i, j;
#define LED PIN_B5
void main(){
output_high(LED);
delay_ms(5000);
output_low(LED);
strcpy(temp2,"km/h"); //change to code after working
while(TRUE){
i=0;
j=0;
while(TRUE){
z=getc();
if(z=='$')
break;
}
z=getc();
if(z=='G')
z=getc();
if(z=='P')
z=getc();
if(z=='V'){
z=getc();
if(z=='T')
z=getc();
if(z=='G')
while(j<7){
z=getc();
if(z==',')
j++;
}
output_high(LED);
while(TRUE){
z=getc();
if(z==',')
break;
temp[i]=z;
i++;
}
strcat(temp,temp2); //change to code after working
i=i+4; //change to code after working
temp[i]='\r';
i++;
/*i++;
temp[i]='\n';*/
temp[i]='\0';
printf(temp);
output_low(LED);
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Guest
|
|
Posted: Fri Sep 18, 2009 6:18 pm |
|
|
Cheers, all very clear now, seems my null terminator is out of place. Fixed and working. Help appreciated |
|
|
santicomp Guest
|
strcat |
Posted: Fri Nov 13, 2009 2:04 pm |
|
|
Hi, I am trying to append 2 strings to do atoi and the int value. But the append does not work. The atoi needs /0 to work. I don't know what I am doing wrong. What is the way to append 2 strings and what is the way to do atoi? Thanks alot.
Code: |
void ciclos(char f,int8 n)
{
int1 num;
int8 i;
int8 l;
char string1[1];
char string2[5];
char *string3;
if (f!=0){
printf(lcd_putc,"%c",f);
strcpy(string1,"\0");
strcpy(string2,f);
*string3=strcat(string1,string2);
l=atoi(string3);
/* switch (f){
case '1':l=1;
break;
case '2':l=2;
break;
case '3':l=3;
break;
case '4':l=4;
break;
case '5':l=5;
break;
case '6':l=6;
break;
case '7':l=7;
break;
case '8':l=8;
break;
case '9':l=9;
break;
}
*/
for (i=1 ; i<=l;i++)
{
delay_ms(300);
actrelay();
delay_ms(300);
dearelay();
}
lcd_putc("\fTerminado");
}
num=0;
} |
|
|
|
|
|
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
|