Chào cả nhà, em đang làm bài tạo 1 ma trận mà kiểu dữ liệu của từng phần tử là kiểu struct và em tạo ma trận bằng cấp phát động. Em tạo được nhưng lúc thêm dữ liệu vào thì visual studio báo lỗi như sau “Unhandled exception at 0x00204D03 in Check 02.exe: 0xC0000005: Access violation writing location 0xCDCDCDCD.” Các bác giúp em được không ạ ? Em cảm ơn ạ !
#include <iostream>
using namespace std;
struct Product
{
//struct Coordinate T;
int OrderNum;
char Name[100];
char Detail[100];
};
void main ()
{
int row = 9;
int col = 10;
Product*** Storage;
Storage = (Product ***)malloc(row * sizeof(Product **)); //cap phat de tao row hang
for (int i = 0; i < row; i++)
{
Storage[i] = (Product **)malloc(col * sizeof(Product*)); //cap phat de tao col. Moi hang lai duoc tao col cot
}
Storage[0][0]->OrderNum = 9;
cout << Storage[0][0]->OrderNum;
}