2
0

strtol.c 977 B

12345678910111213141516171819202122232425262728293031
  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", strtol(" -42", NULL, 0));
  7. printf("%ld\n", strtol(" +555", NULL, 0));
  8. printf("%ld\n", strtol(" 1234567890 ", NULL, 0));
  9. printf("%ld\n", strtol(" -42", NULL, 10));
  10. printf("%ld\n", strtol(" +555", NULL, 10));
  11. printf("%ld\n", strtol(" 1234567890 ", NULL, 10));
  12. printf("%lx\n", strtol(" 0x38Acfg", NULL, 0));
  13. printf("%lx\n", strtol("0Xabcdef12", NULL, 16));
  14. printf("%lx\n", strtol("cafebeef", NULL, 16));
  15. printf("%lo\n", strtol(" 073189", NULL, 0));
  16. printf("%lo\n", strtol(" 073189", NULL, 8));
  17. printf("%lo\n", strtol(" 0b", NULL, 8));
  18. if(errno != 0) {
  19. printf("errno is not 0 (%d), something went wrong\n", errno);
  20. }
  21. printf("%lo\n", strtol(" 0b", NULL, 0));
  22. if(errno != 0) {
  23. printf("errno is not 0 (%d), something went wrong\n", errno);
  24. }
  25. }