7a-struct-char-array.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. struct file
  24. {
  25. char buffer[1];
  26. };
  27. struct xfile
  28. {
  29. char *buffer;
  30. };
  31. struct file file;
  32. struct xfile xfile;
  33. char *buffer = "aaaaaaaaaaaa";
  34. char *bufzor = "bbbbbbbbbbbb";
  35. int
  36. main ()
  37. {
  38. char *p;
  39. struct file *pfile = &file;
  40. strcpy (file.buffer, "0123456789\n");
  41. eputs (file.buffer);
  42. p = pfile->buffer;
  43. if (p[1] != '1')
  44. return 1;
  45. if (file.buffer[1] != '1')
  46. return 2;
  47. if (pfile->buffer[1] != '1')
  48. return 3;
  49. strcpy (file.buffer, "0123456789\n");
  50. eputs (file.buffer);
  51. memcpy (pfile->buffer + 1, " ", 1);
  52. eputs (file.buffer);
  53. if (p[1] != ' ')
  54. return 4;
  55. if (file.buffer[1] != ' ')
  56. return 5;
  57. if (pfile->buffer[1] != ' ')
  58. return 6;
  59. strcpy (file.buffer, "0123456789\n");
  60. eputs (file.buffer);
  61. p[2] = ' ';
  62. eputs (file.buffer);
  63. if (p[2] != ' ')
  64. return 7;
  65. if (file.buffer[2] != ' ')
  66. return 8;
  67. if (pfile->buffer[2] != ' ')
  68. return 9;
  69. strcpy (file.buffer, "0123456789\n");
  70. eputs (file.buffer);
  71. file.buffer[3] = ' ';
  72. eputs (file.buffer);
  73. if (p[3] != ' ')
  74. return 10;
  75. if (p[4] != '4')
  76. return 11;
  77. strcpy (file.buffer, "0123456789\n");
  78. eputs (file.buffer);
  79. pfile->buffer[4] = ' ';
  80. eputs (file.buffer);
  81. if (p[4] != ' ')
  82. return 12;
  83. if (p[5] != '5')
  84. return 13;
  85. xfile.buffer = &buffer;
  86. struct xfile *pxfile = &xfile;
  87. strcpy (xfile.buffer, "0123456789\n");
  88. eputs (xfile.buffer);
  89. p = pxfile->buffer;
  90. if (p[5] != '5')
  91. return 20;
  92. if (xfile.buffer[5] != '5')
  93. return 22;
  94. if (pxfile->buffer[5] != '5')
  95. return 23;
  96. strcpy (xfile.buffer, "0123456789\n");
  97. eputs (xfile.buffer);
  98. memcpy (pxfile->buffer + 5, " ", 1);
  99. eputs (xfile.buffer);
  100. if (p[5] != ' ')
  101. return 24;
  102. if (xfile.buffer[5] != ' ')
  103. return 25;
  104. if (pxfile->buffer[5] != ' ')
  105. return 26;
  106. strcpy (xfile.buffer, "0123456789\n");
  107. eputs (xfile.buffer);
  108. p[6] = ' ';
  109. eputs (xfile.buffer);
  110. if (p[6] != ' ')
  111. return 27;
  112. if (xfile.buffer[6] != ' ')
  113. return 28;
  114. if (pxfile->buffer[6] != ' ')
  115. return 29;
  116. strcpy (xfile.buffer, "0123456789\n");
  117. eputs (xfile.buffer);
  118. xfile.buffer[7] = ' ';
  119. eputs (xfile.buffer);
  120. if (p[7] != ' ')
  121. return 30;
  122. if (p[8] != '8')
  123. return 31;
  124. strcpy (xfile.buffer, "0123456789\n");
  125. eputs (xfile.buffer);
  126. pxfile->buffer[8] = ' ';
  127. eputs (xfile.buffer);
  128. if (p[8] != ' ')
  129. return 32;
  130. if (p[9] != '9')
  131. return 33;
  132. short *ps;
  133. ps = pfile->buffer;
  134. p = pfile->buffer;
  135. strcpy (file.buffer, "0123456789\n");
  136. eputs (file.buffer);
  137. memcpy (ps + 1, " ", 2);
  138. eputs (file.buffer);
  139. eputs (itoa (ps[1]));
  140. eputs ("\n");
  141. eputs (itoa (((' ' << 8) + ' ')));
  142. eputs ("\n");
  143. if (ps[1] != ((' ' << 8) + ' '))
  144. return 40;
  145. if (p[4] != '4')
  146. return 41;
  147. strcpy (file.buffer, "0123456789\n");
  148. eputs (file.buffer);
  149. ps[2] = ((' ' << 8) + ' ');
  150. eputs (file.buffer);
  151. eputs (itoa (ps[2]));
  152. eputs ("\n");
  153. eputs (itoa (((' ' << 8) + ' ')));
  154. eputs ("\n");
  155. if (ps[2] != ((' ' << 8) + ' '))
  156. return 42;
  157. if (p[6] != '6')
  158. return 43;
  159. return 0;
  160. }