Output results to a variable

Below is a code snippet that outputs to the serial monitor - N, NW, E, NNW, etc. I'm trying to get it to output to a variable so that I can then send it to a LCd display.But I can't figure out how.

  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);

The code below did not work.

courseDirection = (gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);

was courseDirection of type char *?

Yes

char courseDirection[5];

I'm new to c and assume char is one character and char courseDirection[5]; allows a string of 5 characters.

char courseDirection[5]; allows a string of 5 characters.

Only 4 characters. A "C string" requires a zero terminator character.

print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);I assume that the print_str() function outputs to the Serial monitor. If so, can you not just modify it to output to the LCD or write a similar function to do so ? Do you actually need the value in a variable at all ?

In your code above you will end up doing one of those 2 statements based on the logic test

courseDirection =   "*** " ;
courseDirection =   TinyGPS::cardinal(gps.f_course()), 6);

Those statements won’t fill in your array…