Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. int myItoa(uint8_t i, char* str, int size) {
  2.     int j = size - 1;
  3.    
  4.     for(; i && j ; j--, i /= 10)
  5.         str[j] = "0123456789"[i % 10];
  6.     return j;
  7. }
  8.  
  9. int myItoa2(int8_t i, char* str, int size) {
  10.     int j = size - 1;
  11.    
  12.     int icpy = i < 0 ? -i : i;
  13.     for(; icpy && j ; j--, icpy /= 10)
  14.         str[j] = "0123456789"[icpy % 10];
  15.     if (i < 0)
  16.       str[j--] = '-';
  17.     return j + 1;
  18. }
  19.  
  20. void write3( char a, uint8_t b, int8_t c )
  21. {
  22.     /* your code goes here */
  23.     write(1, &a, 1);
  24.     write(1, "\n", 1);
  25.    
  26.     char str[32];
  27.     int index = myItoa(b, str, 32);
  28.     write(1, str + index, 32 - index);
  29.     write(1, "\n", 1);
  30.    
  31.     index = myItoa2(c, str, 32);
  32.     write(1, str + index, 32 - index);
  33.     write(1, "\n", 1);
  34.    
  35.     /* avoid 'unused parameter' warning */
  36.     (void)a;
  37.     (void)b;
  38.     (void)c;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement