Hey folks --
DaniWeb has helped me a lot with various other programming projects, but I've run into a snag that I just can't get myself to understand. Hooray for vague compiler errors. Hopefully someone here can show me the error of my ways.
I'm making a little game, based on an external map file. You can traverse from room to room using various directional commands (i.e. north south east west). The "maps.c." file contains eight lines for each room, in this format:
room number
room name
room description
number of connections to other rooms (max: 2)
direction 1
connection1
direction 2
connection 2
In my program, I need to declare an array of structures, one structure for each room, each structure having a place for each piece of information about the room.
Then, I need a function to read the information for a particular room, print that information, and then wait for the user to input where to go next.
I've re-worked this code enough times that my brain is about to explode. The following is an (obviously) incomplete version of how I'm starting things off. I suspect some gross conceptual error, but I can't figure it out. At this point all I want to do is get the program to get the room name and room number, and print 'em.
Thanks a lot for any help.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void readRoom (rooms);
int main (void) {
typedef struct {
int room_num;
char room_name[80];
char desc[1000];
int num_links;
char direction1[6];
int dest1;
char direction2[6];
int dest2;
} roomStruct;
roomStruct rooms[100];
readRoom(rooms);
return 0;
}
void readRoom (rooms[]) {
FILE *fin;
int i = 0;
fin = fopen("maps.c", "r");
fscanf(fin, "%d", &rooms[i].room_num);
fgets(rooms[i].room_name, 80, fin);
printf("Room number: %d ... Room name: %s\n", rooms[i].room_num, rooms[i].room_name);
return;
}