我是新來的C/C++遊戲,所以我認爲我在做一個新手的錯誤:段錯誤中的atoi(STR)
int main(){
char* clen;
clen = getenv("CONTENT_LENGTH");
if (clen==NULL){
cout << "No such ENV var: CONTENT_LENGTH"<<endl;
exit(0);
}
int cl = 0;
cl = atoi(clen);
if (cl < 1){
return inputPage();
}
// if there is no content, we assume that this is a fresh request,
// so we showed the input page, otherwise, we'll return dispatch to
//the processing code.
postTest(clen);
}
這應該是一個CGI腳本。據我可以告訴GDB,打印語句等這段代碼segfaults在行「cl = atoi(clen);」我不知道這是爲什麼。 K & R表明這是正確的。我基本上從其他半數在線教程中複製了這一行。它似乎昨天晚上工作!我完全被難住了。
您發佈的代碼看起來不錯,但它是真實的代碼嗎?您是否將其複製並粘貼到SO中,或者您是否重新輸入了它? – 2009-12-20 19:28:05
複製和粘貼,只需從emacs直接複製和粘貼 – Ben 2009-12-20 19:44:13