Advertisement
Guest User

?

a guest
Apr 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "dungeon.h"
  5.  
  6. char st[50];
  7. char dup[50];
  8. int count = 1;
  9.  
  10. struct dungeon_t *roomlist;
  11.  
  12. //WHAT DAFUQ IS WRONG
  13. int get_room(char* name) {
  14. int r;
  15.  
  16. for (int i=0; i<count; i++) {
  17. if (strcmp(name, roomlist[i].room_name) == 0) {
  18. r = i;
  19. }
  20. }
  21. printf("%d\n", r);
  22.  
  23. return r;
  24. }
  25.  
  26.  
  27. int main(int argc, char* argv[]) {
  28.  
  29. FILE *file = fopen(argv[1],"r");
  30.  
  31. int i=0;
  32.  
  33.  
  34.  
  35. while(fgets(st, sizeof st, file) != NULL){
  36.  
  37. if (i == 0) {
  38.  
  39. for (int j = 0;st[j] != '\0';j++) {
  40. if (st[j] == ' ') {
  41. count++;
  42. }
  43.  
  44. }
  45.  
  46. roomlist = calloc(count, sizeof(dungeon_t));
  47. strncpy(dup, st, strlen(st)-1); //THIS SHOULD REMOVE THE NEWLINE!
  48. char *p = strtok (dup, " \n");
  49.  
  50. int ind = 0;
  51. while (p != NULL) {
  52.  
  53. roomlist[ind].room_name = p;
  54. p = strtok (NULL, " \n");
  55. ind++;
  56. }
  57.  
  58. }
  59.  
  60. else {
  61.  
  62. strncpy(dup, st, strlen(st)-1);
  63. char *split = strtok (dup, " >");
  64. int index = 0;
  65.  
  66. char *init;
  67. char *direction;
  68. char *link;
  69. while (split != NULL) {
  70. if (index == 0) {
  71.  
  72. init = split;
  73. printf("%s\n", roomlist[get_room(init)].room_name);
  74. }
  75.  
  76. else if (index == 1) {
  77. direction = split;
  78. printf("%s\n", direction);
  79. }
  80.  
  81. //HIGHLY PROBLEMATIC.
  82. else if (index == 2) {
  83.  
  84. printf("%s\n", split);
  85. printf("%s\n", roomlist[get_room(link)].room_name);
  86.  
  87.  
  88. }
  89. split = strtok (NULL, " \n>");
  90. index++;
  91. printf("\n");
  92.  
  93. }
  94.  
  95. }
  96.  
  97.  
  98. i++;
  99.  
  100. }
  101.  
  102.  
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement