[問題] strtok的問題
遇到的問題: (題意請描述清楚)
strtok讀取結果未如預期
希望得到的正確結果:
In the class, store:1,05:11:11,06:50:12
In the class, name: 1
In the class, starttime: 05:11:11
In the class, endtime: 06:50:12
程式跑出來的錯誤結果:
In the class, store:1,05:11:11,06:50:12
In the class, name: 1
In the class, starttime: ,
In the class, endtime: ,
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
visual studio 2008
有問題的code: (請善用置底文標色功能)
void cTrainTime::setTrain(char *n)
{
char *tempname, *tempstart, *tempend;
printf("In the class, store:%s\n",n);
tempname = strtok(n,",");
tempstart = (NULL, ",");
tempend = (NULL, ",");
printf("In the class, name:%s \n",tempname);
printf("In the class, starttime:%s \n",tempstart);
printf("In the class, endtime:%s \n",tempend);
};
補充說明:
請問各位先進 以上程式碼中的觀念是否出錯
怎麼會跑出" , " QQ
另外,我想針對上述的時間以秒的方式做計算,
但是他們目前狀態是char 要怎麼轉換比較方便呢?
(現在只想到一個字一個字對照ASCII換 @@)
謝謝各位了^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.122.114.59
→
11/28 22:05, , 1F
11/28 22:05, 1F
→
11/28 22:05, , 2F
11/28 22:05, 2F
→
11/28 22:11, , 3F
11/28 22:11, 3F
→
11/28 22:57, , 4F
11/28 22:57, 4F
→
11/28 23:00, , 5F
11/28 23:00, 5F
推
11/29 00:06, , 6F
11/29 00:06, 6F
推
11/29 00:52, , 7F
11/29 00:52, 7F
→
11/29 01:08, , 8F
11/29 01:08, 8F
討論串 (同標題文章)