精華區beta Programming 關於我們 聯絡資訊
※ 引述《TKyo.bbs@ptt.cc (暗黑貴公子)》之銘言: > ※ 引述《streitleak.bbs@aeug.twbbs.org (亞斯爾‧馮‧修特萊)》之銘言: > : 還沒比對勒 > ....... Orz > : 有沒有意義我想這由上頭判斷 反正他要啥我就給他啥.... > 嗯 > : 現在的問題是把每行的資料丟到STRUCT中要花1秒的時間...... > : 是讀一行並解析全部的動作加起來一秒 如果能更快當然更好 ... > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 這種速度太誇張的慢了 > 你需要講清楚 "讀取 -> 解析" 的程式碼/動作, 不然無法解決你的問題 LoadOtherDataToArray(void) { char tmpStr[500],tmpCaller[20],tmpCallee[20],sttime[20],entime[20],tmp[30],tmp2[10]; char NC,NC2; int tmpSeconds; struct tm tmptm; struct tm tmptm2; int i=0; FILE *fp; clock_t start=0,end=0; switch(WhichOne) { case 1: try { if(( fp=fopen(ITP_Main->OtherFILE.c_str(),"r"))== NULL ) return false; // for( int i=0;i<ITP_Main->OtherCDR->Lines->Count;i++ ) while( !feof(fp) ) { start=clock(); ITP_Main->Label212->Caption=AnsiString(start); SrcData[i].CallerID[0]='\0'; SrcData[i].CalleeID[0]='\0'; SrcData[i].StartTime=0; SrcData[i].EndTime=0; SrcData[i].Next = NULL; // strcpy(tmpStr,ITP_Main->OtherCDR->Lines->Strings[i].c_str()); fgets(tmpStr,500,fp); strncpy(&NC,tmpStr,1); strncpy(&NC2,tmpStr+1,1); if( atoi(&NC)== 0 && atoi(&NC2)==0 ) { continue; } /* for( int j=0;j<strlen(tmpStr);j++ ) { if( tmpStr[j]=='\t' ) tmpStr[j]=' '; }*/ sscanf(tmpStr,"%20s %20s %30s %20s %20s %07s",tmpCaller,tmpCallee,tmp,sttime,entime,tmp2); strcpy(SrcData[i].CallerID, tmpCaller); strcpy(SrcData[i].CalleeID, tmpCallee+1); sscanf(sttime,"%04d%02d%02d-%02d%02d%02d", &tmptm.tm_year, &tmptm.tm_mon, &tmptm.tm_mday, &tmptm.tm_hour, &tmptm.tm_min, &tmptm.tm_sec); sscanf(entime,"%04d%02d%02d-%02d%02d%02d", &tmptm2.tm_year, &tmptm2.tm_mon, &tmptm2.tm_mday, &tmptm2.tm_hour, &tmptm2.tm_min, &tmptm2.tm_sec); SrcData[i].StartTime=mktime(&tmptm); SrcData[i].EndTime=mktime(&tmptm2); SrcData[i].Seconds = atoi(tmp2); ITP_Main->ProgressBar1->Position++; ITP_Main->StatusBar1->Panels->Items[3]->Text = AnsiString(i); // Sleep(10); if( i<ITP_Main->OtherCDR->Lines->Count ) i++; end=clock(); ITP_Main->Label213->Caption=AnsiString(end); ITP_Main->Label214->Caption=AnsiString(start-end); }; fclose(fp); } catch(...) { ShowMessage("Link List Error!"); fclose(fp); return false; } -- Origin: 幽谷˙反地球聯邦組織 aeug.twbbs.org Author: streitleak211-20-33-61.HINET-IP.hinet.net 發表
FlyinDeath:strncpy(&NC,tmpStr,1); //第一次看到這種寫法 囧rz 01/13 15:20
godfat:一堆很神的用法 01/13 17:05