kahou
asked on
time
Hi,
I am write a program about the difference of two given times.
First, I need to retrieve the time(year, month , day, hour ,min, sec) from the file. And then I need to find the time different in the file.
However, those data in the file is string. So I need to convert them to int in order to assign in the time structure. This is tedious!
Do you guys have any good idea so I can get rid of this tediou method?
Thanks
I am write a program about the difference of two given times.
First, I need to retrieve the time(year, month , day, hour ,min, sec) from the file. And then I need to find the time different in the file.
However, those data in the file is string. So I need to convert them to int in order to assign in the time structure. This is tedious!
Do you guys have any good idea so I can get rid of this tediou method?
Thanks
above should read:
char *smonth = "THE VALUE YOU READ IN";
int imonth = (int) smonth;
ech
char *smonth = "THE VALUE YOU READ IN";
int imonth = (int) smonth;
ech
Please shoot me for being an absolute moron... I am incorrect in what I previously told you... you would have to get the ASCII value of character you read in and convert it to int.
sorry
i am being stupid today.
sorry
i am being stupid today.
>> ...in the time structure.
Why don't you simply read and write entire structures to disk using fread() and fwrite()?
Exceter
Why don't you simply read and write entire structures to disk using fread() and fwrite()?
Exceter
ASKER
If I use fread and fwrite, it still read the string. However, how to assign it into integer.
for instance:
if the file is written as,
2003 FEB 21 12 23 32
where 12 is hour,23 is minutes, 32 is second and 21 is date.
and this time is generated by localtime(). So if the time is generated in the morning. the time will only have 1 - 9 but not 01 - 09. This will make it tedious when I try to convert this string into int.
for instance:
if the file is written as,
2003 FEB 21 12 23 32
where 12 is hour,23 is minutes, 32 is second and 21 is date.
and this time is generated by localtime(). So if the time is generated in the morning. the time will only have 1 - 9 but not 01 - 09. This will make it tedious when I try to convert this string into int.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
say the value you read in form month is stored in char *month, which is month = "12"... depending on exactly what youy want could you do something like...
char *month = "THE VALUE YOU READ IN";
int imonth = (int) smonth;
etc..
does this help at all or am i way off base here?
echard