90-strtol.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <mes/lib.h>
  21. #include <stdlib.h>
  22. int
  23. main ()
  24. {
  25. eputs ("0x12\n");
  26. if (strtol ("0x12", 0, 0) != 18)
  27. 1;
  28. eputs ("012\n");
  29. if (strtol ("012", 0, 0) != 10)
  30. 2;
  31. eputs ("-1\n");
  32. if (strtol ("-1", 0, 0) != -1)
  33. 3;
  34. eputs ("-1\n");
  35. if (strtoul ("-1", 0, 0) != -1)
  36. 4;
  37. char *p = "16";
  38. int n = strtol (p, (char **) &p, 0);
  39. eputs ("p=");
  40. eputs (p);
  41. eputs ("\n");
  42. if (*p != 0)
  43. return 5;
  44. p = "0x12";
  45. n = strtol (p, (char **) &p, 0);
  46. eputs ("p=");
  47. eputs (p);
  48. eputs ("\n");
  49. if (*p != 0)
  50. return 5;
  51. return 0;
  52. }