strtoul.c 938 B

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