根據DDD我從strcpy中得到一個seg錯誤,但我無法弄清楚我做錯了什麼(對C來說還是很新的)。任何幫助將不勝感激,在此先感謝。strcpy Seg Fault
int compare_people(PERSON* first, PERSON* second)
{
char firstName[32];
char secondName[32];
strcpy(firstName, first->name);
strcpy(secondName, second->name);
int returnVal = strcmp(firstName, secondName);
return returnVal;
}
如果name是超過31個字符長,將會寫入無效的內存,因爲你做的緩衝區是唯一的那麼大。 – mukunda 2014-12-01 21:45:41
這些名字平均只有5-10個字符 – Sammdahamm 2014-12-01 21:46:02
我猜'first'或'second'是'NULL'。使用調試器。 – 2014-12-01 21:46:44