[問題] 字元
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux C
問題(Question):
自己已經把問題結決 但是還是不懂 原本的為何邏輯是錯的
程式碼(Code):(請善用置底文網頁, 記得排版)
struct Tran_GPS {
char time[24];
//int id;
};
int main()
{
struct Tran_GPS tran1;
strcpy(tran1.time, "2012/05/15-13:27:30.791");
//tran1.time[18]存的是 0
int totalmsecond=(int)(tran1.time[18]);
printf("%d\n",totalmsecond);
}
預期想要printf出來的是0 但 最後出來的是48
char *c=&tran1.time[18];
int totalmsecond=atoi(c);
printf("%d\n",totalmsecond);
後來改成上面程式碼 才是出來0
後面改的程式碼 我知道原理
但問題是不太懂為啥 我最開始的打法是錯的?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.164.79
推
06/29 11:26, , 1F
06/29 11:26, 1F
→
06/29 11:35, , 2F
06/29 11:35, 2F
推
06/29 11:38, , 3F
06/29 11:38, 3F
→
06/29 11:38, , 4F
06/29 11:38, 4F
→
06/29 11:51, , 5F
06/29 11:51, 5F
→
06/29 11:51, , 6F
06/29 11:51, 6F
推
06/29 22:18, , 7F
06/29 22:18, 7F
推
07/02 13:01, , 8F
07/02 13:01, 8F
討論串 (同標題文章)