My problem is that I want to do in a function C happens to me an integer less than 100 (ie two digits) to a string of two characters:
23 -> 23
5 -> 05
And more that I try, do not know how to do it. The truth is it was never my strong handling strings with C. So happened to me one way but I have problems with the function and, of course, the handling of characters for the return value, you get part of my code to see if I put help or should I go for another forms.
Code:char * pasarMinutos (int minutes) ( char length [3]; / * declare string of three characters who will be the maximum * / int first, second; length [3] = '\ 0'; / * put the character string at the end of the last position * / if (minutes> 9) / * if the digit is two numbers * / ( first = (int) (minutos/10); / * calculate the first number * / if (first == 1) / * and since I'm going aki putting the first character according to the num * / ( LENGTH [1] = "1"; ) else if (first == 2) ( LENGTH [1] = "2"; ) ............................................... else if (first == 9) ( LENGTH [1] = "9"; ) second = (min-first * 10); / * calculate the second num * / if (second == 1) / * and the same thing with the first q * / ( LENGTH [2] = "1"; ) else if (second == 2) ( LENGTH [2] = "2"; ) ...................................... ) else if (second == 9) ( LENGTH [2] = "9"; ) ) else / * if the number is only one-digit * / ( LENGTH [1] = "0" / * the first character will be a 0 * / second = minutes; / * and from aki ago as in the previous * / if (second == 1) ( LENGTH [2] = "1"; ) else if (second == 2) ( LENGTH [2] = "2"; ) .................................... else if (second == 9) ( LENGTH [2] = "9"; ) ) return length; );
Bookmarks