全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:8891
推到 Plurk!
推到 Facebook!

BCB讀取TXT檔案問題

尚未結案
nimama
一般會員


發表:1
回覆:0
積分:0
註冊:2010-02-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-02-07 21:23:16 IP:61.227.xxx.xxx 訂閱
我使用BCB讀取TXT檔案,
但式讀取出來的資料都是錯誤的。,
麻煩高手為我解答。

TXT檔案內容
-----------------
1
2
5
10
24
-----------------



[code c#]

int X[255];
int Count=0;
FILE *stream;
char FirstLine[255];
int I;
OpenDialog1->Options.Clear();
OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist;
OpenDialog1->Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
// OpenDialog1->FilterIndex = 2; // start the dialog showing all files

if (OpenDialog1->Execute())
{
for (I=0; IFiles->Count; I )
{
stream=fopen(OpenDialog1->Files->Strings[I].c_str(), "r");
if (stream)
{
while(fgets(FirstLine, sizeof(FirstLine), stream)!=NULL)
{
char *p;
p = strtok(FirstLine," ");
while(p!=NULL)
{
scanf(p,"%d",&X[Count]); //讀入座標字串至x 變數中
Memo1->Lines->Add(StrToInt(X[Count]));
Count ;
p = strtok(NULL," ");
}
}
Edit2->Text=Count; //顯示點資料數
fclose(stream);
}
}
}
請在此區域輸入程式碼

[/code]
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-02-09 13:53:17 IP:203.75.xxx.xxx 未訂閱
不知道你想要得到什麼樣的結果
但是memo有提供讀入txt的方法

[code cpp]
OpenDialog1->Options.Clear();
OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist;
OpenDialog1->Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
OpenDialog1->FilterIndex = 2; // start the dialog showing all files
if (OpenDialog1->Execute())
{
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
Edit1->Text = Memo1->Lines->Strings[0];
}
[/code]

===================引 用 nimama 文 章===================
我使用BCB讀取TXT檔案,
但式讀取出來的資料都是錯誤的。,
麻煩高手為我解答。

TXT檔案內容
-----------------
1
2
5
10
24
-----------------
李國維
高階會員


發表:42
回覆:287
積分:235
註冊:2003-02-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-02-10 10:29:14 IP:61.67.xxx.xxx 訂閱

要不要試試看使用TStringList來讀取

[code cpp]
TStringList *SLTmp = new TStringList();
SLTmp->LoadFormFile("C:\\test.txt");
for ( int i = 0 ; i < SLTmp->Count ; i )
{
Memo1->Lines->Add(SLTmp->Strings[i]);

}
delete SLTmp;
[/code]
===================引 用 nimama 文 章===================
我使用BCB讀取TXT檔案,
但式讀取出來的資料都是錯誤的。,
麻煩高手為我解答。

TXT檔案內容
-----------------
1
2
5
10
24
-----------------



[code c#]

int X[255];
int Count=0;
FILE *stream;
char FirstLine[255];
int I;
OpenDialog1->Options.Clear();
OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist;
OpenDialog1->Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
// OpenDialog1->FilterIndex = 2; // start the dialog showing all files

if (OpenDialog1->Execute())
{
for (I=0; I
if (stream)
{
while(fgets(FirstLine, sizeof(FirstLine), stream)!=NULL)
{
char *p;
p = strtok(FirstLine," ");
while(p!=NULL)
{
scanf(p,"%d",&X[Count]); //讀入座標字串至x 變數中
Memo1->Lines->Add(StrToInt(X[Count]));
Count ;
p = strtok(NULL," ");
}
}
Edit2->Text=Count; //顯示點資料數
fclose(stream);
}
}
}
請在此區域輸入程式碼

[/code]
ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-02-12 08:44:39 IP:140.116.xxx.xxx 訂閱
Memo1->Lines->Add(StrToInt(X[Count]));
應該不用StrToInt吧??
X[Count] 不就是 int 嗎?


------
FPGA驗證, FPGA開發平台, http://smims.com
系統時間:2024-03-29 7:18:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!