I am trying to use malloc
to first allocate some space for an array, and then realloc
to extend the array. The program compiles but I get some strange memory-print in the terminal when I run the program. The terminal says someting like: ======== Memory map =========
and then a bunch of numbers and stuff.
In my program, I use malloc as this:
struct station *addStation(struct station *graph, struct station newStation){
graph = realloc(graph, sizeof(graph)+sizeof(struct station));
// Count the rows of graph[] here and add newStation to the end.
}
int main(){
struct station *graph;
graph = malloc(145*sizeof(struct station));
graph = loadStations();
newStation = graph[27];
graph = addStation(graph, newStation);
}
Am I using it wrong?