i have written a program to get the time from the gps . As we all know , the gps gives the output as 010203(01:02:03) . when i put this number into a formula for converting into hours , 010203 is taken as an octal number and not as 10203 and messes the calculation as arduino directly converts to decimal . how to suppress that leading 0 in this case ? my code is as given below
the value i am obtaining is from the gps . using tinygps library and newsoftware serial . it gives (1:02:03) as 010203 . so this value is recieved directly from the gps . after recieving this value i want to remove the leading 0 . because when i put this value it directly uses octal arithmetic . i want 010203 to remain as 10203 .
The time returned by the GPS in the code you will use is a binary integer - it's not represented as character digits, so it is meaningless to talk about it having a leading zero. However, one of the quirks of the C language is that when you write an integer literal, if you provide a leading zero then the compiler interprets it in octal. So all you need to to is not use leading zeros when you specify a constant such as 10203 in your tests.
If the time you get from the GPS/TinyGPS class IS 010203, that is a string, not a numeric value. They are NOT interchangeable. The string can be converted to a numeric value, but the number will NOT have a leading 0/be treated as octal.
#include "TinyGPS.h"
TinyGPS gps;#define RXPIN 3 #define TXPIN 2
SoftwareSerial nss(RXPIN, TXPIN);
void loop()
{
while (nss.available())
{
int c = nss.read();
if (gps.encode(c))
{
// process new gps info here
}
}
This is the initial code for the setup and reading NMEA data ..
then we go on to write
// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);
time and date is initialized as
unsigned long fix_age, time, date, speed, course;
so its an integer not a string .. tiny gps and softwareserial libraries make sure of that ..
Post ALL of your code. Where are you printing date and time? It's likely, bordering on certainty, that THAT is where the leading 0 is being added. It is NOT part of the binary data that is stored in the memory location that the variable is pointing to.
oh ok .. there was this function get.crack_datetime which wasnt working .. i got it to work and differentiate hour second and minute , year , month and day...
it does not give with a preceding 0 . thanks .. here is the code for reference . thanks alot guys . cheers .