fork(5) download
  1. #include <stdio.h>
  2.  
  3. int divBytesBy10(unsigned char* bytes, size_t count, unsigned char* remainder)
  4. {
  5. unsigned carryOver = 0;
  6. int nonZeroQuotient = 0;
  7.  
  8. while (count--)
  9. {
  10. carryOver = carryOver * 256 + *bytes;
  11. *bytes = carryOver / 10;
  12. carryOver %= 10;
  13.  
  14. nonZeroQuotient |= *bytes++;
  15. }
  16.  
  17. *remainder = '0' + carryOver; // convert to ASCII right here
  18. return nonZeroQuotient;
  19. }
  20.  
  21. int main(void)
  22. {
  23. unsigned char num[] = {0xFF, 0xFF, 0xFF, 0xFF}, rem, cnt = 0;
  24. char str[11], *p = str + sizeof(str) - 1;
  25. *p = '\0';
  26. while (divBytesBy10(num, sizeof(num), --p)) {}
  27. printf("%s\n", p);
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
4294967295