Fixed world storge problems
This commit is contained in:
parent
36834b58b7
commit
8d3254c5d6
2 changed files with 9 additions and 4 deletions
|
|
@ -3,10 +3,10 @@
|
|||
Room* wrld__create() {
|
||||
Room *rooms = malloc(WORLD_SIZE * sizeof(*rooms));
|
||||
|
||||
for (unsigned int i = 0; i < WORLD_SIZE; i++) {
|
||||
char strbuf[(int)log10(WORLD_SIZE) + 1 + 80];
|
||||
snprintf(strbuf, sizeof(strbuf), "Room name: %d",i);
|
||||
|
||||
for (unsigned int i = 0; i < WORLD_SIZE; ++i) {
|
||||
//char strbuf[(int)log10(WORLD_SIZE) + 1 + 12];
|
||||
char* strbuf = malloc(sizeof (char) * ((int)log10(WORLD_SIZE) + 1 + 12));
|
||||
snprintf(strbuf, sizeof (char) * ((int)log10(WORLD_SIZE) + 1 + 12), "Room name: %d",i+1);
|
||||
rooms[i].name = strbuf;
|
||||
rooms[i].description = strbuf;
|
||||
rooms[i].north = NULL;
|
||||
|
|
@ -19,5 +19,9 @@ Room* wrld__create() {
|
|||
}
|
||||
|
||||
void wrld__destroy(Room* rooms){
|
||||
for (unsigned int i = 0; i < WORLD_SIZE; ++i) {
|
||||
free(rooms[i].name);
|
||||
free(rooms[i].description);
|
||||
}
|
||||
free(rooms);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#define WORLD_SIZE 100
|
||||
|
||||
#include <math.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue