util.c 442 B

1234567891011121314151617181920212223
  1. void memory_copy(char *source, char *dest, int nbytes) {
  2. int i;
  3. for (i = 0; i < nbytes; i++) {
  4. *(dest + i) = *(source + i);
  5. }
  6. }
  7. /**
  8. * K&R implementation
  9. */
  10. void int_to_ascii(int n, char str[]) {
  11. int i, sign;
  12. if ((sign = n) < 0) n = -n;
  13. i = 0;
  14. do {
  15. str[i++] = n % 10 + '0';
  16. } while ((n /= 10) > 0);
  17. if (sign < 0) str[i++] = '-';
  18. str[i] = '\0';
  19. /* TODO: implement "reverse" */
  20. }