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

picking out certain characters from a string

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



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

picking out certain characters from a string
PostPosted: Fri Apr 04, 2008 6:37 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 04, 2008 9:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 12:12 pm     Reply with quote

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.
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