Adding Date in a file - C -



Adding Date in a file - C -

i'm coding network game in c. 've written scores in file. wanted add together date of day. here file's construction : date name score , code :

scorefile = fopen("scores.txt", "a"); fprintf(scorefile, "%s %d\n", name, score);

i've tried system("date") it's printed on stdout. think can't add together date fprintf.

do know solution permits add together date in file ? (maybe time.h ?)

thanks lot !!

consider using strftime convert time construction string.

example (from link above):

#include <time.h> // ... char s[30]; size_t i; struct tm tim; time_t now; = time(null); tim = *(localtime(&now)); = strftime(s,30,"%b %d, %y; %h:%m:%s\n",&tim);

puts jul 9, 2011; 17:55:55\n in s

c file date file-io time.h

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -