vs使用malloc配置設定空間報斷點,求大神解答
void LoadMapDate()
{
BusMap_g.bus_num = bus_num;
BusMap_g.buses = (Bus*)malloc(sizeof(Bus) * bus_num);//在這它就報斷點了
int i;
for (i = 1;i <= bus_num;i++)
{
strcpy(BusMap_g.buses[i].name, bus[i].name);
BusMap_g.buses[i].start = -1;
BusMap_g.buses[i].end = -1;
}
BusMap_g.station_num = sta_num;
BusMap_g.stations = (Station*)malloc(sizeof(Station) * sta_num);
for (i = 1;i <=sta_num;i++)
{
strcpy(BusMap_g.stations[i].station, station[i].station);
BusMap_g.stations[i].routes = NULL;
}
//添加公交資訊
for (i = 1;i <= bus_num;i++)
AddBus(bus[i].num,bus[i].start,bus[i].end);
for (i = 1;i <= rou_num;i++)
AddRoute(route[i].busnum, route[i].stationstart, route[i].stationend, route[i].distance);
}
代碼中兩個malloc均報斷點,我試了各種方法都不行,求大神指教一下🥺