strtoul.c 926 B

123456789101112131415161718192021222324252627282930
  1. #include <errno.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. int main(void) {
  5. printf("%ld\n", strtoul(" -42", NULL, 0));
  6. printf("%ld\n", strtoul(" +555", NULL, 0));
  7. printf("%ld\n", strtoul(" 1234567890 ", NULL, 0));
  8. printf("%ld\n", strtoul(" -42", NULL, 10));
  9. printf("%ld\n", strtoul(" +555", NULL, 10));
  10. printf("%ld\n", strtoul(" 1234567890 ", NULL, 10));
  11. printf("%lx\n", strtoul(" 0x38Acfg", NULL, 0));
  12. printf("%lx\n", strtoul("0Xabcdef12", NULL, 16));
  13. printf("%lo\n", strtoul(" 073189", NULL, 0));
  14. printf("%lo\n", strtoul(" 073189", NULL, 8));
  15. printf("%lo\n", strtoul(" 0b", NULL, 8));
  16. if(errno != 0) {
  17. printf("errno is not 0 (%d), something went wrong\n", errno);
  18. }
  19. printf("%lo\n", strtoul(" 0b", NULL, 0));
  20. if(errno != 0) {
  21. printf("errno is not 0 (%d), something went wrong\n", errno);
  22. }
  23. return 0;
  24. }