線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1399
推到 Plurk!
推到 Facebook!

特殊的檔案格式

尚未結案
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-01 21:06:08 IP:61.230.xxx.xxx 未訂閱
有一檔案很奇怪,用記事本打開時看到的是一堆亂碼,用fgets,fread讀也讀不出來,不知該怎麼辦??? 只知道用vb讀時,要用Open file For Random As #3 Len=4,問題就在這Random 查了一下bcb help,找不到有關Random的文件,不知那位大大知道,能指點一下嗎??
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-01 22:59:25 IP:61.62.xxx.xxx 未訂閱
你應該採用 binary mode 來開檔案: FILE *fp = fopen("test.dat", "rb"); 以下擷取 BCB HELP 關於 fopen 的說明: Prototype FILE *fopen(const char *filename, const char *mode); FILE *_wfopen(const wchar_t *filename, const wchar_t *mode); Description Opens a stream. fopen opens the file named by filename and associates a stream with it. fopen returns a pointer to be used to identify the stream in subsequent operations. The mode string used in calls to fopen is one of the following values: Value Description r Open for reading only. w Create for writing. If a file by that name already exists, it will be overwritten. a Append; open for writing at end-of-file or create for writing if the file does not exist. r Open an existing file for update (reading and writing). w Create a new file for update (reading and writing). If a file by that name already exists, it will be overwritten. a Open for append; open (or create if the file does not exist) for update at the end of the file. To specify that a given file is being opened or created in text mode append a t to the mode string (rt w t and so on). Similarly to specify binary mode append a b to the mode string (wb a b and so on). fopen also allows the t or b to be inserted between the letter and the character in the mode string; for example rt is equivalent to r t.
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-02 10:26:08 IP:210.62.xxx.xxx 未訂閱
可是我用Fread讀出來還是亂碼,怎麼辦呢????
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-02 10:55:51 IP:61.230.xxx.xxx 未訂閱
binary 的檔案本來大多就不會拿來存文字檔案呀,像是 .exe, .jpg, .bmp 都是儲存成 binary,你也不能把它讀出來當文字看,binary 檔案應該都有自行定義屬於他們自己解讀的方式才對。
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-02 19:35:31 IP:218.160.xxx.xxx 未訂閱
引言: 有一檔案很奇怪,用記事本打開時看到的是一堆亂碼,用fgets,fread讀也讀不出來,不知該怎麼辦??? 只知道用vb讀時,要用Open file For Random As #3 Len=4,問題就在這Random 查了一下bcb help,找不到有關Random的文件,不知那位大大知道,能指點一下嗎??
1.Random是隨機檔,dos版的basic,c 的書大都會提到,但寫法是因人而異,沒有原版的程式,就比較難知道它的計算方法. 2.你知道用vb讀時,要用Open file For Random As #3 Len=4,我想你一定有原始程式,何不post上來看看,假如不方便,片斷程式也可.
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-12-02 20:29:42 IP:218.167.xxx.xxx 未訂閱
我知道它是4個bytes一組,我用fread來讀,還是解不出和vb一樣的結果,我快要起笑了~~~~ 挖~要怎麼把檔案附上去呢? 發表人 -
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-12-02 20:49:13 IP:61.62.xxx.xxx 未訂閱
這有說明: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=19268
benson5033
一般會員


發表:44
回覆:47
積分:18
註冊:2004-08-16

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-12-02 21:29:25 IP:61.230.xxx.xxx 未訂閱
我已經將檔案放至http://delphi.ktop.com.tw/topic.php?TOPIC_ID=60805,請幫我看看
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-12-02 21:41:32 IP:61.62.xxx.xxx 未訂閱
有 VB 的原始碼嗎?光靠這個檔案實在不知道這個檔案的結構是怎樣咧? 你 VB 程式讀出來的資料顯示在畫面上是長怎樣?
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-12-02 22:01:56 IP:218.160.xxx.xxx 未訂閱
依你的資料,應該是股票的資料,每個資料是 36 bytes  
typedef struct
{
  unsigned long d; //日期
  unsigned long o,h,l,c; //開,高,低,收
  unsigned long a;
  unsigned long b;
  unsigned long c;
  unsigned long d;
} AA;    FILE *fp;
AA a;
//讀檔:
fread(&a,sizeof(AA),1,fp);
 
系統時間:2024-06-18 22:02:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!