init.c 957 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. typedef struct { int codes[3]; char name[6]; } Word;
  2. Word words[] = {
  3. 1, 2, 3, "if",
  4. { { 4, 5 }, { 'f', 'o', 'r' } },
  5. 6, 7, 8, {"else"},
  6. { { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', },
  7. { 0 },
  8. }, *wordlist = words;
  9. int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };
  10. int *y[] = { x[0], x[1], x[2], 0 };
  11. main()
  12. {
  13. int i, j;
  14. for (i = 0; y[i]; i++) {
  15. for (j = 0; y[i][j]; j++)
  16. printf(" %d", y[i][j]);
  17. printf("\n");
  18. }
  19. f();
  20. g(wordlist);
  21. return 0;
  22. }
  23. f() {
  24. static char *keywords[] = {"if", "for", "else", "while", 0, };
  25. char **p;
  26. for (p = keywords; *p; p++)
  27. printf("%s\n", *p);
  28. }
  29. g(p)
  30. Word *p;
  31. {
  32. int i;
  33. for ( ; p->codes[0]; p++) {
  34. for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++)
  35. printf("%d ", p->codes[i]);
  36. printf("%s\n", p->name);
  37. }
  38. h();
  39. }
  40. h()
  41. {
  42. int i;
  43. for (i = 0; i < sizeof(words)/sizeof(Word); i++)
  44. printf("%d %d %d %s\n", words[i].codes[0],
  45. words[i].codes[1], words[i].codes[2],
  46. &words[i].name[0]);
  47. }