70-printf-simple.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,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 <stdio.h>
  22. #include <string.h>
  23. #include <stdarg.h>
  24. int
  25. main ()
  26. {
  27. char *s = "mes";
  28. char c = 'm';
  29. int i = 3;
  30. char buf[20];
  31. printf ("c=%c\n", c);
  32. sprintf (buf, "c=%c\n", c);
  33. if (strcmp (buf, "c=m\n"))
  34. return 1;
  35. if (i != 3)
  36. return 2;
  37. printf ("i=%d\n", i);
  38. sprintf (buf, "i=%d\n", i);
  39. if (strcmp (buf, "i=3\n"))
  40. return 3;
  41. printf ("s=%s\n", s);
  42. sprintf (buf, "s=%s\n", s);
  43. if (strcmp (buf, "s=mes\n"))
  44. return 4;
  45. sprintf (buf, "%u", -1);
  46. eputs ("buf=");
  47. eputs (buf);
  48. eputs ("\n");
  49. #if __i386__
  50. if (strcmp (buf, "4294967295"))
  51. return 5;
  52. #elif __x86_64__
  53. if (strcmp (buf, "18446744073709551615"))
  54. return 6;
  55. #endif
  56. sprintf (buf, ">>%o<<\n", 12);
  57. eputs ("buf=");
  58. eputs (buf);
  59. if (strcmp (buf, ">>14<<\n"))
  60. return 7;
  61. sprintf (buf, ">>%x<<\n", 12);
  62. eputs ("buf=");
  63. eputs (buf);
  64. if (strcmp (buf, ">>c<<\n"))
  65. return 8;
  66. sprintf (buf, ">>%X<<\n", 12);
  67. eputs ("buf=");
  68. eputs (buf);
  69. if (strcmp (buf, ">>C<<\n"))
  70. return 9;
  71. return 0;
  72. }