僅執行以下操作會導致分段錯誤。 它可能是argv或argc的東西? 真的失去了。提前致謝!客戶端程序中的分段錯誤
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#define MESSAGE "Not so important message"
int main(int argc, char * argv[])
{
printf(argc);
return 0;
}
請參閱下面的答案(儘管可能有其他錯誤)。但是你可以通過一個調試器來發現這種問題,它會向你顯示段錯誤的發生。同樣格式化你的代碼,'if(hp!= NULL)'中條件代碼的格式非常差。 –
感謝邁克爾,謝謝,我知道,如果(hp!= NULL)不是我應該使用的條件,但它只是當我最初擁有它(hp == NULL)時,seg故障仍然發生困惑我是因爲我認爲segfault是由於試圖解引用一個NULL hp而引起的,所以我只想看看是否(hp!= NULL)爲真,並且「Here 6」將被打印,但是無論我使用的是否打印語句執行如果(hp == NULL)或if(hp!= NULL),那麼segfault可能來自其他地方? – David