Sunday 15 August 2010

string - split hhmmss to hh mm ss in c -


I have an integer 002345 to say that I want to divide it into hours = 0 min = 23 sec = 45. "/" And "%" formulas, but since the first two positions, it was unable to work 00 There is no other way. None of you presents me with a code. Thank you

Since you are not asking the traditional method of using "/" and "%" You can then change the integer time for the string and bar out time, minutes, seconds.

But not accumulating time as a simple integer is not a good idea, you will remember the leading zero for hours. So it's better to use a four array.

  #include & lt; Stdio.h & gt; #include & lt; String.h & gt; Int main () {four hours [3] = {0}; Four minutes [3] = {0}; Four seconds [3] = {0}; Int Time = 2345; Char timeStr [10] = {0}; Sprintoff (timstrutter, "% 06d", time); Memcopy (Hour, Time, STR, 2); Memcpy (min, time + 2 + 2); Mempie (second, timeST +4,2); Printf ("% s:% s:% s", hours, minutes, seconds); }   

The way I recommend: -

  #include & lt; Stdio.h & gt; #include & lt; String.h & gt; Int main () {four hours [3] = {0}; Four minutes [3] = {0}; Four seconds [3] = {0}; Char timeStr [] = "002345"; Memcopy (Hour, Time, STR, 2); Memcpy (min, time + 2 + 2); Mempie (second, timeST +4,2); Printf ("% s:% s:% s", hours, minutes, seconds); }   

then atoi (); using hours in the integer,

No comments:

Post a Comment