Magic Lantern Forum

Developing Magic Lantern => General Development => Topic started by: wolf on January 13, 2013, 10:56:49 PM

Title: SOLVED sprintf I don't know what to do :)
Post by: wolf on January 13, 2013, 10:56:49 PM
Unfortunately I use in my special timelaps-plugin the sprintf command to update the menu which displays the duration of the TL.

With which command is it done today when sprintf is deprecated?
As you see I'm not a very good programmer and thankful for any advice.


UPDATE:
When I use snprintf(time_str,10, "%02d%s%02d%s%02d",hours,colon,minutes,colon,seconds );
I get depending on the time result something like following displayed in the menu:
e p e p
or  p e p e p e p e

SOLVED:
snprintf(time_str, sizeof(time_str), "%02d%s%02d%s%02d",hours,colon,minutes,colon,seconds );

outside of ML with gcc it works

(http://i.imgur.com/rk7oK.png?1)


...
{
        .name = "Duration",
        .priv = &v,
        .max = 0,
        .choices = (const char *[]) {time_str},
        .help = "",
    },

...

char* sec_to_time(int seconds)
{
    int minutes, hours;
    hours=seconds % 86400 / 3600;
    minutes=seconds % 3600 / 60;
    seconds=seconds % 60;
    const char colon[] = ":";
    sprintf(time_str, "%02d%s%02d%s%02d",hours,colon,minutes,colon,seconds );
    return time_str;
}
...



with GCC it works for me

#include <stdio.h>

main()
{
    char time_str [ 10 ];
    int minutes, hours, len;
    int seconds =199999000;
    hours=seconds % 86400 / 3600;
    minutes=seconds % 3600 / 60;
    seconds=seconds % 60;
    const char colon[] = ":";
    snprintf(time_str,10, "%02d%s%02d%s%02d",hours,colon,minutes,colon,seconds );
    printf("%s  \n", time_str);
}