Re: [問題] 二階指標的動態記憶體

看板C_and_CPP (C/C++)作者 (City*Mate)時間16年前 (2009/10/18 11:46), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串3/3 (看更多)
嗯嗯 我已經弄好了 那另外請教 如果 int **buf1_num; int **buf1_cof; fp = fopen("input.txt", "r"); fscanf (fp, "%d" ,&k); buf1_num=(int**)malloc( 2*k ); buf1_cof=(int**)malloc( 2*k ); for (i=0;i<2*k;i++) { y=0; fscanf(fp, "%d %d",&a,&b); while (a!=0 || b!=0) { y++; buf1_num[i]=(int*)malloc(2*sizeof y+1); buf1_cof[i]=(int*)malloc(2*sizeof y+1); fscanf(fp, "%d %d\n",&a,&b); } 我想要把buf1_num buf1_cof 全部清空都變為零要怎麼弄 一定要用loop嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.249.122

10/18 12:05, , 1F
calloc or memset
10/18 12:05, 1F

10/18 12:05, , 2F
malloc(單位byte)1個int佔幾byte?通常用sizeof確定型態
10/18 12:05, 2F

10/18 12:06, , 3F
while裡面重複malloc沒有free
10/18 12:06, 3F
文章代碼(AID): #1Ase-5kn (C_and_CPP)
文章代碼(AID): #1Ase-5kn (C_and_CPP)