-3
我在執行時遇到段錯誤。下面是代碼和bt的gdb輸出。 代碼在崩潰之前一直運行到結束。 衝突似乎與我的開關/箱段錯誤 - >在std :: basic_ostream中<char,std :: char_traits <char>
char *getmybuyData()
{
FILE *fp = popen("php orders.php 155", "r");
if (fp == NULL) perror ("Error opening file");
char buydbuff[BUFSIZ];
bool more = true;
do {
vector<string> vrecords;
for (int i = 0; (i < 7) && (more = (fgets(buydbuff, BUFSIZ, fp) != NULL)); ++i) {
size_t n = strlen(buydbuff);
if (n && buydbuff[n - 1] == '\n')
buydbuff[n - 1] = '\0';
//push everything into vector
if (buydbuff[0] != '\0')
vrecords.push_back(buydbuff);
//begine breaking down the data;
}
for (int n = 0; n < 7; ++n){
switch(n){
case 0:
cout << vrecords[0] << endl;
break;
case 1:
cout << vrecords[1] << endl;
break;
case 2:
cout << vrecords[2] << endl;
break;
case 3:
cout << vrecords[3] << endl;
break;
case 4:
cout << vrecords[4] << endl;
break;
case 5:
cout << vrecords[5] << endl;
break;
case 6:
cout << vrecords[6] << endl;
break;
case 7:
cout << vrecords[7] << endl;
break;
default:
//cout << "Hello World" << endl;
break;
}
}
} while (more);
}
輸出:
198397652
2014-11-14 15:10:10
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198397685
2014-11-14 15:10:13
Buy
0.00517290
0.00100000
0.00100000
0.00000517
198398295
2014-11-14 15:11:14
Buy
0.00517290
0.00100000
0.00100000
0.00000517
203440061
2014-11-21 16:13:13
Sell
0.00825550
0.00100000
0.00100000
0.00000826
Segmentation fault
GDB輸出: enter link description here
函數的* line *是指向哪個堆棧跟蹤(也就是第45行)? – 2014-11-23 12:49:13
你的'案例7'永遠不會被執行,'default'也不會被執行。 – 2014-11-23 12:50:06
[在過去48小時內]發佈此任務上的問題(http://stackoverflow.com/users/4272671/bro?tab=questions)將提示您可能需要對語言基礎進行審查。該輸出for循環有點證實了這一觀察。 – WhozCraig 2014-11-23 13:05:14