I have a file with a single string of 150 characters. The string consists of combinations that either refers to room dimensions, door placement or item placement for a rogue game.
I have successfuly opened the file, read the string, tokenized the string by spaces, stored each token into a 2 dimensional string called **storage, and passed over **storage to a function without errors.
Below is the code I am using in the new function to break up the first string in **stored, which is 10X16, and print out the room borders using ncurse. The problem is that I am getting a segmentation fault, but I have no idea where it is coming form. Also, is there a better way to do this?
Code:
int counter = 0;
char * token = malloc(sizeof(char *) * 151);
int x = 0;
int y = 0;
if(strcmp(storage[counter], "1") == 0 || strcmp(storage[counter], "2") == 0 || strcmp(storage[counter], "3") == 0 || strcmp(storage[counter], "4") == 0 || strcmp(storage[counter], "5") == 0 || strcmp(storage[counter], "6") == 0 || strcmp(storage[counter], "7") == 0 || strcmp(storage[counter], "8") == 0 || strcmp(storage[counter], "9") == 0)
{
token = strtok(storage[counter], "X");
x = atol(token);
token = strtok(NULL, "X");
y = atol(token);
/* blank screen refresh */
clear();
move(0,0);
refresh();
for(counter = 0; counter != x; counter++)
{
mvaddch(0, counter, '=');
mvaddch(y, counter, '=');
}
for(counter = 1; counter != y; counter++)
{
mvaddch(counter, 0, '=');
mvaddch(counter, x, '=');
}
move(0,0);
refresh();
}
Thanks for your time and help ahead of time.