我试图使用malloc
首先为数组分配一些空间,然后realloc
扩展数组。该程序可以编译,但是当我运行该程序时,我在终端中得到了一些奇怪的内存打印。终端说一些类似的东西:======== Memory map =========
然后是一堆数字和东西。
在我的程序中,我使用 malloc 如下:
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);
}
我用错了吗?