View previous topic :: View next topic |
Author |
Message |
madtoilet
Joined: 02 Apr 2008 Posts: 36
|
picking out certain characters from a string |
Posted: Fri Apr 04, 2008 6:37 pm |
|
|
Code: |
void disp_rmc(void)
{
int i=0;
int k=0;//16
int j=0;//27
int l=4;
int h=5;
char temp1[70];
char temp2[70];
char longitude[16]="long";
char lattitude[14]="lat";
strcpy(temp1, rmc);
for(i=0;i < 11; i++){
lattitude[l]= temp1[k];
k++;
l++;
}
for(i=0; i< 12; i++){
longitude[h]= temp1[j];
j++;
h++;
}
clear();
cursor_position(0x80);
out_lcd_string(longitude);
cursor_position(0xC0);
out_lcd_string(lattitude);
}
|
this is my current code
i'm trying to pick out certain parts of a sentence (rmc) that i have copied into temp1. it's not working for both cases. Is there some way i can do this?[/quote] |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Apr 04, 2008 9:09 pm |
|
|
You're initialising your longitude and lattitude (latitude) strings to "long" and "lat" respectively. Taking longitude, the code equivalent is: Code: | longitude[0] = 'l';
longitude[1] = 'o';
longitude[2] = 'n';
longitude[3] = 'g';
longitude[4] = 0; // string terminator |
When copying into the string you're starting at position 5, after the string terminator.
Either add a space at the end of the initialisers so you start by copying over the string terminator, or adjust your starting point back one.
In either case, don't forget to terminate the string when you're finished copying, eg Code: | longitude[h] = 0;
lattitude[l] = 0; |
_________________ Andrew |
|
|
madtoilet
Joined: 02 Apr 2008 Posts: 36
|
|
Posted: Tue Apr 08, 2008 12:12 pm |
|
|
hey thanks a bunch! that helped me and i now display the right information.
however, even though i add
longitude = 0; at the last one it gives me some rubbish characters at the end of the string when i display it.
*edit i am sorry. i fixed it. |
|
|
|