71-struct-array.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017 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 foo;
  24. struct foo *krak;
  25. typedef struct foo foo_struct;
  26. struct foo
  27. {
  28. int bar[2];
  29. char name[10];
  30. };
  31. struct foo g_foo;
  32. int a, b;
  33. int i, *j;
  34. int *k = 0, l;
  35. typedef struct baz
  36. {
  37. int bar;
  38. //struct baz *f, *g;
  39. struct baz *f;
  40. struct baz *g;
  41. } baz;
  42. int
  43. main ()
  44. {
  45. foo_struct f;
  46. f.bar[0] = 0x22;
  47. f.bar[1] = 0x34;
  48. printf ("eentje: %d\n", f.bar[0]);
  49. printf ("tweetje: %d\n", f.bar[1]);
  50. int *pf = &f;
  51. if (*pf != 0x22)
  52. return 1;
  53. if (*(pf + 1) != 0x34)
  54. return 2;
  55. struct foo *g = &f;
  56. printf ("punter eentje: %d\n", g->bar[0]);
  57. printf ("punter tweetje: %d\n", g->bar[1]);
  58. char *strings[] = { "one\n", "two\n", "three\n", NULL };
  59. char **p = strings;
  60. while (*p)
  61. oputs (*p++);
  62. if (strcmp (strings[1], "two\n"))
  63. return 3;
  64. strcpy (f.name, "hallo\n");
  65. oputs (f.name);
  66. struct foo fu;
  67. strcpy (fu.name, "hello\n");
  68. oputs (fu.name);
  69. strcpy (g_foo.name, "hey\n");
  70. oputs (g_foo.name);
  71. char buf[10];
  72. struct foo *s = &buf;
  73. strcpy (s->name, "hi\n");
  74. oputs (s->name);
  75. return 0;
  76. }