i'm currently trying to debug my program over UART by printing the values of some variables at specific points. My issue is with printing two char arrays. The order in which i print them seems to have an effect on if it prints. The declarations of the arrays are in a struct in a header file as follows-
//header file
typedef struct
{
char latitude[10];
char longitude[11];
}NMEA_RMC_t;
NMEA_RMC_t rmc;
The char arrays are manipulated in another function after parsing data from an input. They are not updated with an interrupt, although there are interrupts elsewhere in the program. In the main code if i print them as follows-
//main program loop
printf("lat: %s \t long: %s \n", rmc.latitude, rmc.longitude);
the output to the terminal is this-
lat: +50.71735 long:
whereas if i print them in a different order like this-
printf("long: %s \t lat: %s \n", rmc.longitude, rmc.latitude);
i get this output.
long: -001.39118 lat:
also if i split the printing up into two separate printf statements, only the first print statement correctly prints the char array. I haven't had to ask for help on here before but this has had me stuck for a good week now. Any help would be massively appreciated! cheers.
edit
The part of the program that writes into the array is this. its essentially the same for the latitude and longitude array.
/* now we are in first char of latitude */
/* copy latitude chars */
strlcpy ((char*)lat, (const char*)ptr_to_comma, 10 );/*copies most size-1, null terminated*/ //changed 11 to 10
/* default latitude presentation is ddmm.mmmmm
we need to change it to dd.mmmmmmm
*/
unsigned char ind;
for (ind=0; ind<9; ind++)
{
if (*ptr_to_comma == '.')
{
ptr_to_comma++;//step over '.'
}
if ( ind==2 )
{
lat[ind++]='.';
}
lat[ind] = *ptr_to_comma;
ptr_to_comma++;
}
lat[10] = '\0'; //terminate
/* now lat == dd.mmmmmmm */
ptr_to_comma++; /*step over comma to the NS-indicator*/
/*catch NorthSouth-indicator and step*/
if ( *ptr_to_comma == 'N'){ /*if we are in the North*/
sign = '+';
rmc.ns_indicator = 'N';
} else if ( *ptr_to_comma == 'S'){ /*else we are in the South*/
sign = '-';
rmc.ns_indicator = 'S';
}
ptr_to_comma++;//step over NS-indicator
ptr_to_comma++;//step over comma to the longitude field
/* dd.mmmmmmm to dd.ddddddd */
_convert_minutes( (unsigned char*) lat+3 );
/* copy latitude with sign to the rmc-struct */
rmc.latitude[0] = sign;
strcpy ( (char*)rmc.latitude+1, (const char*)lat);
rmc.latitude[10]='\0';
essentially it is parsing the information from a stream of data coming in.
rmc.latitude[10]='\0'
actually put '\0' to longitude[0]. Tryrmc.latitude[9]='\0'
- wyc