Ahmed B.Kahla
Ahmed B.Kahla

Reputation: 1

save a file name with date format yyyy_mm_dd hh_mm_ss

i'm working on a project with Raspberry and opencv, i want to save a picture taken by the camera pi with the date system. i'm programming with c and i used ctime but i don't get the format yyyy_mm_dd hh_mm_ss, here is my code.`

    time_t t = time(NULL);
    printf("%s\n", ctime(&t));
    sprintf (nmphoto, "images/%d%s.jpg", sequence++,ctime(&t));
    cvSaveImage(nmphoto,userdata.image2,p);`

i would like to use this methode

  time_t rawtime;
    struct tm * timeinfo;
    char buffer [80];
    time (&rawtime);
    timeinfo = localtime (&rawtime);
    strftime (buffer,80,"Now it's %I:%M:%S.",timeinfo);
    puts (buffer); 

but i don't know how to deal with the buffer and concat it with the sequence++ which is the id of the picture. any suggestions please.

Upvotes: 0

Views: 696

Answers (1)

Frane
Frane

Reputation: 534

try to use:

sprintf (nmphoto, "images/%d%s.jpg", sequence++, buffer);

It will place the string in buffer in place %s.

Upvotes: 2

Related Questions