Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "dungeon.h"
- char st[50];
- char dup[50];
- int count = 1;
- struct dungeon_t *roomlist;
- //WHAT DAFUQ IS WRONG
- int get_room(char* name) {
- int r;
- for (int i=0; i<count; i++) {
- if (strcmp(name, roomlist[i].room_name) == 0) {
- r = i;
- }
- }
- printf("%d\n", r);
- return r;
- }
- int main(int argc, char* argv[]) {
- FILE *file = fopen(argv[1],"r");
- int i=0;
- while(fgets(st, sizeof st, file) != NULL){
- if (i == 0) {
- for (int j = 0;st[j] != '\0';j++) {
- if (st[j] == ' ') {
- count++;
- }
- }
- roomlist = calloc(count, sizeof(dungeon_t));
- strncpy(dup, st, strlen(st)-1); //THIS SHOULD REMOVE THE NEWLINE!
- char *p = strtok (dup, " \n");
- int ind = 0;
- while (p != NULL) {
- roomlist[ind].room_name = p;
- p = strtok (NULL, " \n");
- ind++;
- }
- }
- else {
- strncpy(dup, st, strlen(st)-1);
- char *split = strtok (dup, " >");
- int index = 0;
- char *init;
- char *direction;
- char *link;
- while (split != NULL) {
- if (index == 0) {
- init = split;
- printf("%s\n", roomlist[get_room(init)].room_name);
- }
- else if (index == 1) {
- direction = split;
- printf("%s\n", direction);
- }
- //HIGHLY PROBLEMATIC.
- else if (index == 2) {
- printf("%s\n", split);
- printf("%s\n", roomlist[get_room(link)].room_name);
- }
- split = strtok (NULL, " \n>");
- index++;
- printf("\n");
- }
- }
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement