How to make serial.print into a varibale

Below is code we found from this site that works great. How ever we are having difficulty taking the parsed GPS and putting the LAT and LONG into a variable format. Any ideas or code out there that could help us? Also does the serial need to be printed each time or can we omit it to save space?

  if(bien==6){               // If yes, continue and process the data
         for (int i=0;i<300;i++){
           if (linea[i]==','){    // check for the position of the  "," separator
             // note: again, there is a potential buffer overflow here!
             indices[cont]=i;
             cont++;
           }
           if (linea[i]=='*'){    // ... and the "*"
             indices[12]=i;
             cont++;
           }
         }
         Serial.println("");      // ... and write to the serial port
         Serial.println("");
         Serial.println("---------------");
         for (int i=0;i<12;i++){
           switch(i){
             //case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
             case 1 :Serial.print("Status (A=OK,V=KO): ");break;
             case 2 :Serial.print("Latitude: ");break;
             case 3 :Serial.print("Direction (N/S): ");break;
             case 4 :Serial.print("Longitude: ");break;
             case 5 :Serial.print("Direction (E/W): ");break;
             case 6 :Serial.print("Velocity in knots: ");break;
             //case 7 :Serial.print("Heading in degrees: ");break;
             //case 8 :Serial.print("Date UTC (DdMmAa): ");break;
             //case 9 :Serial.print("Magnetic degrees: ");break;
             //case 10 :Serial.print("(E/W): ");break;
            // case 11 :Serial.print("Mode: ");break;
             //case 12 :Serial.print("Checksum: ");break;
           }

Also does the serial need to be printed each time or can we omit it to save space?

Omit what?

Have you considered sprintf?

AWOL:

Also does the serial need to be printed each time or can we omit it to save space?

Omit what?

Have you considered sprintf?

I have been messing around with it but have been unsuccessful in implementing it. I do not know where I would put it and how to integrate it into the different cases or the serial.prints.

I have been messing around with it but have been unsuccessful in implementing it.

Where is that code?

Basically, like this:

      char variable = Serial.read();

replace the char with your desired datatype.

clarkmcc:
Basically, like this:

      char variable = Serial.read();

replace the char with your desired datatype.

Can I do something like this?

float latitude;
latitude=sprintf(Serial.print("Latitude: "));break;

Well you can do it but it won't do what you think.

Here is how Adafruit does it in their GPS library
(Just a snippet of the relevant code)

  if (strstr(nmea, "$GPGGA")) {
    // found GGA
    char *p = nmea;
    // get time
    p = strchr(p, ',')+1;
    float timef = atof(p);
    uint32_t time = timef;
    hour = time / 10000;
    minute = (time % 10000) / 100;
    seconds = (time % 100);

    milliseconds = fmod(timef, 1.0) * 1000;

    // parse out latitude
    p = strchr(p, ',')+1;
    latitude = atof(p);

    p = strchr(p, ',')+1;
    if (p[0] == 'N') lat = 'N';
    else if (p[0] == 'S') lat = 'S';
    else if (p[0] == ',') lat = 0;
    else return false;

    // parse out longitude
    p = strchr(p, ',')+1;
    longitude = atof(p);

    p = strchr(p, ',')+1;
    if (p[0] == 'W') lon = 'W';
    else if (p[0] == 'E') lon = 'E';
    else if (p[0] == ',') lon = 0;
    else return false;

    p = strchr(p, ',')+1;
    fixquality = atoi(p);

    p = strchr(p, ',')+1;
    satellites = atoi(p);

    p = strchr(p, ',')+1;
    HDOP = atof(p);

    p = strchr(p, ',')+1;
    altitude = atof(p);
    p = strchr(p, ',')+1;
    p = strchr(p, ',')+1;
    geoidheight = atof(p);
    return true;
  }

mrburnette:
https://github.com/adafruit/Adafruit-GPS-Library
Here is how Adafruit does it in their GPS library
(Just a snippet of the relevant code)

  if (strstr(nmea, "$GPGGA")) {

// found GGA
    char *p = nmea;
    // get time
    p = strchr(p, ‘,’)+1;
    float timef = atof(p);
    uint32_t time = timef;
    hour = time / 10000;
    minute = (time % 10000) / 100;
    seconds = (time % 100);

milliseconds = fmod(timef, 1.0) * 1000;

// parse out latitude
    p = strchr(p, ‘,’)+1;
    latitude = atof(p);

p = strchr(p, ‘,’)+1;
    if (p[0] == ‘N’) lat = ‘N’;
    else if (p[0] == ‘S’) lat = ‘S’;
    else if (p[0] == ‘,’) lat = 0;
    else return false;

// parse out longitude
    p = strchr(p, ‘,’)+1;
    longitude = atof(p);

p = strchr(p, ‘,’)+1;
    if (p[0] == ‘W’) lon = ‘W’;
    else if (p[0] == ‘E’) lon = ‘E’;
    else if (p[0] == ‘,’) lon = 0;
    else return false;

p = strchr(p, ‘,’)+1;
    fixquality = atoi(p);

p = strchr(p, ‘,’)+1;
    satellites = atoi(p);

p = strchr(p, ‘,’)+1;
    HDOP = atof(p);

p = strchr(p, ‘,’)+1;
    altitude = atof(p);
    p = strchr(p, ‘,’)+1;
    p = strchr(p, ‘,’)+1;
    geoidheight = atof(p);
    return true;
  }

Thank you!

Grumpy_Mike:
Well you can do it but it won't do what you think.

how would I go about doing it what I think? Thanks.

hlhowns:

Grumpy_Mike:
Well you can do it but it won't do what you think.

how would I go about doing it what I think? Thanks.

telepathy features have not yet been enabled on this forum.

are you thinking about Strings ?
do you want to have a fixed "sentence" made as a variable to be called whenever you need it ?

hlhowns:
how would I go about doing it what I think? Thanks.

float latitude;
latitude=sprintf(Serial.print("Latitude: "));break;

well:-

char latitude[] = "Latitude: ";

Would do it.