Loading...
Pages: [1]   Go Down
Author Topic: How to save a letter from a char array to a string?  (Read 331 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 152
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,
I am using the GPS GM862 to send my gps location. I have manage to get the numbers but I cannot serial.print the North/South /East/West.
Code:
char GPSLAT[20];
char LAT[10];
long LATI;
long LAT1;
long LONGI;
long LATI1;
long LATI2;
long LATI3;
char LATI4;


strncpy(GPSLAT,&inData[12],9);

      strncpy(LAT,&GPSLAT[0],2);
      LATI1=atoi(LAT);
      Serial.println("LATI");   
      Serial.println(LATI1);
      strncpy(LAT,&GPSLAT[2],2);
      LATI2=atoi(LAT);
      Serial.println(LATI2);
      strncpy(LAT,&GPSLAT[5],4);
      LATI3=atoi(LAT);
      Serial.println(LATI3);
     strcpy(LAT,&GPSLAT[9],1);
      LATI4=atoi(LAT);           // Which is the right command? (I know this command is to convert a string to an integer, I need to convert to string!)
      Serial.println(LATI4);     // this never prints the letter, it oesn;t print anything. What to do?

Can someone help me with the right command?   
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 336
Posts: 36476
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
     strcpy(LAT,&GPSLAT[9],1);
You are copying one character into a 10 element array. Why not just use
Code:
LATI4 = GPSLAT[9];
Then,
Code:
Serial.println(LATI4);
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 152
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It prints nothing doing it that way.... To be right it prints " ".I just want the N or S letter. (North/South)

How can I print the letter?

The array that i have copied to another array is this one
inData=
 234956.000,3800.6894N,02348.1036E,1.0,207.8,3,12.08,0.36,0.19,190312,07


I want to be able to serial.print N/S for the latitude.
Can someone help?
« Last Edit: March 19, 2012, 06:58:37 pm by nathanas » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 336
Posts: 36476
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How can I print the letter?
Given no sample data to look at, all I can assume is that the direction letter is NOT in position 9 in the array.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 152
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Its in Number 9 because when i print the
 GPSLAT[8]; it gives me number "4" which is the previous one.
GPSLAT[9]; it gives me " ",instead of comma "N"
GPSLAT[10]; it gives me  " ", instead of comma ","
« Last Edit: March 19, 2012, 07:10:28 pm by nathanas » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 152
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The array should be larger, that was the problem..... thanks for your time anyway...
Logged

Pages: [1]   Go Up
Print
 
Jump to: