So I've had this problem I've been trying to solve for about 8 hours now... I've given up my search for an answer without help. I've tried using realloc()
and malloc()
respectively, so any input would be great!
The purpose of this being in C is to allow for the creation of a 'map', I will later be using ncurses to create the map.
the input from the file is as follows
10X16 de4 dw9 ds8 g8,7 m3,4 h6,5 p2,2
6X20 dn5 ds4 W4,3 e2,12 M1,1
10X13 ds3 dw9
10X12
5X4
6x12
Here is the code:
char *importLevel()
{
FILE *fPointer;
fPointer = fopen("Level", "r"); //Opens text file to read
char* rooms[150];// set up for memory allocation
char commands[150];// set up for pulling data from read file
while (!feof(fPointer))
{
fgets(commands,150, fPointer); // this takes each line from the file
}
*rooms = (char *) malloc(150 * sizeof(char)); // memory allocation
for (int i = 0; i < 150; i++)
{
if (rooms[i] != NULL)
{
*rooms[i] = commands[i]; // supposed to give rooms the string
}
}
fclose(fPointer);// close file
return *rooms; // return pointer
}
I hope I'm not as stupid as I feel right now! Thanks :)
edit: I AM as stupid as I felt right then