[問題] 關於struct的讀取與寫入

看板C_and_CPP作者 (尖頭鰻)時間13年前 (2011/01/18 13:21), 編輯推噓0(005)
留言5則, 4人參與, 最新討論串1/1
請教一下各位大大.. struct存取的方是我非常陌生 希望大大們能給我個指示 以下是我寫的函式 struct Data { INT32U thing1; INT32U thing2; } struct Data A; void Write_Data() { INT16S fp; struct Data *txt_addr1=&A; fp=open((CHAR *)"a:\\Bingo.txt",O_WRONLY|O_CREAT);//開啟nand flash的文件檔 write(fp,(INT32U)txt_addr1,sizeof(A));//將資料的位置寫到nand flash close(fp); } void Read_Data() { INT16S fp1; struct Data *txt_addr1=NULL; fp1=open((CHAR *)"a:\\Bingo.txt",O_RDONLY|O_CREAT);//開啟nand flash的文件檔 txt_addr1 = (struct Data*)gp_malloc_align(sizeof(A), 4); read(fp1,(INT32U)txt_addr1,sizeof(A));//將資料的位置從nand flash讀取 A = *txt_addr1; close(fp1); } 為何這樣讀出來都是亂碼呢???可以給我個幫助 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.228.157 ※ 編輯: SuperEel 來自: 59.120.228.157 (01/18 13:21)

01/18 13:34, , 1F
你知道 txt_addr1 是在做什麼的嗎?
01/18 13:34, 1F

01/18 13:36, , 2F
怪怪的碼
01/18 13:36, 2F

01/18 13:37, , 3F
不用allocate一塊空間給txt_addr1嗎? 0.0
01/18 13:37, 3F
※ 編輯: SuperEel 來自: 59.120.228.157 (01/18 13:45)

01/18 13:45, , 4F
是改成這樣給他配置空間嗎???
01/18 13:45, 4F

01/18 13:47, , 5F
txt_addr1紀錄Data的記憶體位置?
01/18 13:47, 5F
※ 編輯: SuperEel 來自: 59.120.228.157 (01/18 13:48)
文章代碼(AID): #1DDID1XE (C_and_CPP)