By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,173 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,173 IT Pros & Developers. It's quick & easy.

Convert time represented as a string to seconds

P: 1
I have the code to convert a string into a int (the atoi function) but it only gives me the first number say if the time is 6:23:08 it only returns the number 6 but I need to change all of this to seconds.
Jan 23 '07 #1
Share this Question
Share on Google+
3 Replies


P: 40
I have the code to convert a string into a int (the atoi function) but it only gives me the first number say if the time is 6:23:08 it only returns the number 6 but I need to change all of this to seconds.


Fetch the hour field, mins field ans seconds field separately by using memcpy function and then convert each to atoi... you will get the ans....
Jan 23 '07 #2

Axon
P: 7
I have the code to convert a string into a int (the atoi function) but it only gives me the first number say if the time is 6:23:08 it only returns the number 6 but I need to change all of this to seconds.
Try using
int hrs = 0;
int mins = 0;
int secs = 0;
string time = "12:34:02";
sscanf("%d:%d:%d", time, hrs, mins, secs);
Jan 23 '07 #3

Expert 100+
P: 1,510
Try using
int hrs = 0;
int mins = 0;
int secs = 0;
string time = "12:34:02";
sscanf("%d:%d:%d", time, hrs, mins, secs);
sscanf() parameters were not correct, try
Expand|Select|Wrap|Line Numbers
  1. int hrs = 0;
  2. int mins = 0;
  3. int secs = 0;
  4. char time[] = "12:34:02";
  5. sscanf(time, "%d:%d:%d", &hrs, &mins, &secs);
  6.  
Jan 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.