[問題] 檔案IO的segmentation fault
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
LINUX
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MAP
問題(Question):
底下是一隻將文字檔中的資料逐筆讀出,再將它們寫進MAP中的一段程式
MAP的型態為<string,wkSCNGDAType>
一筆資料長度包含'\n'為24個bytes
這個程式在第二次WHILE迴圈的時候會出現segfault
確定是執行第二次FILE_SCNGDA.getline(recordContent,record_length,'\n');的時候報
錯的,用GDB看了一下發現當時FILE_SCNGDA的值為FILE_SCNGDA = <incomplete type>
,實在百思不得其解到底出錯的原因是什麼,希望眾位高手可以幫忙看看
餵入的資料(Input):
無
預期的正確結果(Expected Output):
順利結束
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
void DATALOAD()
{
int key_length; //MAP的KEY值長度
int record_length; //一筆RECORD的長度
char keyContent[5];
char recordContent[24];
static int current_pos=0;
/**********************build SCNGDA map************************************/
fstream FILE_SCNGDA("SCNGDA.TXT",ios::in);
key_length=4; record_length=24;
wkSCNGDAType wkSCNGDATypeS; //結構變數
while( !FILE_SCNGDA.eof())
{
FILE_SCNGDA.getline(recordContent,record_length,'\n');
current_pos += record_length;
FILE_SCNGDA.seekg(current_pos);
recordContent[record_length-1]='\0';
memcpy( &keyContent[0], &recordContent[0],4);
keyContent[key_length]='\0';
memcpy( &wkSCNGDATypeS.SCG_BROKER_ID[0], &keyContent[0], 5);
wkSCNGDATypeS.SCG_TODAY=StrTOLong(&recordContent[5],8);
wkSCNGDATypeS.SCG_YESTERDAY=StrTOLong(&recordContent[14],8);
wkSCNGDAColl[keyContent]=wkSCNGDATypeS; //塞進MAP
}
FILE_SCNGDA.close();
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.218.212.227
推
04/18 16:35, , 1F
04/18 16:35, 1F
→
04/18 16:35, , 2F
04/18 16:35, 2F
→
04/18 17:02, , 3F
04/18 17:02, 3F
→
04/18 17:06, , 4F
04/18 17:06, 4F
→
04/18 17:07, , 5F
04/18 17:07, 5F
→
04/18 17:08, , 6F
04/18 17:08, 6F
→
04/18 17:10, , 7F
04/18 17:10, 7F
→
04/18 17:11, , 8F
04/18 17:11, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章