I have a character array, or string, that has a series of...'X'...' '...'F'...'S'...
I have a maze (only one level) where the walls are marked with X's, the walkable space is marked with a space and the start and finish are S and F respectively. I have to read in the maze file in, then make it a 2D array. here is some of my code...
Code:
typedef struct MazeStruct
{
char **maze; // 2D maze map
int row; // row of the map
int col; // column of the map
int start_row; // row of the starting point
int start_col; // column of the starting point
} Maze;
//this is the prototype given to me by my instructor. It returns a 1 if successful or a -1 if not.
int GenerateMaze(char* filename, Maze *Mymaze)
{
if ((fr=fopen(filename,"r")) == NULL) {
printf("%s could not be found\n",filename);
return -1;
}
char coords[30];
char *tokptr;
int row, col; **the file has the dimension of the maze at the top
fgets(coords,15,filename); **so i use strtok() when i know what the 'token' is
tokPtr = (strtok(coords, ","));
row = atoi(tokptr); //get rows
tokPtr = (strtok(NULL, ","));
col = atoi(tokptr); //get cols
Mymaze->row = row;
Mymaze->col = col;
//Maze allocation **not sure how accurate this chunk of code is
char **Mz;
int i;
Mz = (int**)malloc(row*sizeof(int*))
for (i=0; i<col; i++)
Mz[i] = (int*)malloc(col*sizeof(int));
char line[100];
int c,k, counter = 0;
**this is where I was going to put the maze into the 2Darray
**but idk how to take one character at a time
for (c=0; c<Mymaze->row;c++) {
fgets(line, sizeof(line), filename);
for (k=1; k<Mymaze->col; k++)
}
}
Also, if there is a way to take a single character at a time from a file, that would work as well...
Thanks!