[Repost in new thread, as a forum bump doesn't seem to work :)]
Having discovered sprintf (see here), I realised that it was idea for my time conversion function, see this thread. So I took the plunge, and converted it, and it worked for a while, but now something has gone wrong!
This function is passed an integer number of seconds, and returns a text string " HH:MM" derived from it. But it doesn't work anymore; I guess I'm doing something dumb!
Note that txt4[4] and txt7[7] are global scratchpad variables.
The calls to sprintf() return the value 3, so that bit is working. But the function returns something like "255:256"
Having discovered sprintf (see here), I realised that it was idea for my time conversion function, see this thread. So I took the plunge, and converted it, and it worked for a while, but now something has gone wrong!
This function is passed an integer number of seconds, and returns a text string " HH:MM" derived from it. But it doesn't work anymore; I guess I'm doing something dumb!
Note that txt4[4] and txt7[7] are global scratchpad variables.
Code:
char * formatHours(int seconds) { // convert integer seconds timer to string: " HH:MM" byte hrs, mins ; int fullmins ; char time[7] = " " ; // leading space fullmins = seconds / 60 ; // convert seconds to minutes hrs = fullmins / 60 ; // convert minutes into hours mins = fullmins % 60 ; // remainder of same division is minutes sprintf(txt4, "%02d", hrs) ; // format 2 places, leading zero strcat(time, txt4) ; // add to time string strcat(time, ":") ; // add a colon sprintf(txt4, "%02d", mins) ; // format 2 places, leading zero strcat(time, txt4) ; // return (strcpy(txt7, time)) ; }
Comment