I want to read a date from a text file in a single variable/array in this format :
Thu Feb 05 16:48:30 2015
to print i used :
fprintf (savegame,"Played Date : %s ",ctime(&time1));
but what to do scan ?
Ok . so i probably said something very wrong so i will just reformulate like a task what i get from school... :
I have a text file which contains:
Played Date : Thu Feb 05 16:48:30 2015 Played Date : Thu Jan 01 02:00:00 1970
I want to put them each in a single variable then delete
Played Date :
print them and update to the current date.
Is there any way to do this?
Edit : I tried with:
fscanf (savegame,"Played Date : %s ",ctime(&time1));
but doesn't work....
In POSIX, you can parse a date using
strptime(), into a value of type
You'd first read the entire line of text from the file (
fgets() is the best choice for that), then pass that to
If you have static non-date text on the line, you need to skip that first. If it's static, you can just add its length to a pointer to the line, and pass that to
strptime(). You can also include the text in the format string to
strptime(), and it will be skipped.