我有什麼,我認爲比較麻煩的是段錯誤,當我試圖訪問一個字符串的特定元素。具體來說,我試圖在'經度'末尾確定這封信,並檢查它是否是'W'。但是,在我到達strcmp部分之前,我最終崩潰了。 下面的代碼:定位在一個字符串的元素,在C
int main{
int Val;
char longitude[20] = "081-28-23.2590W";
char direction = longitude[14]; //pretty sure it's crashing on this line
printf("%s\n", direction); //this does not print
Val = strcmp(direction, "W"); //And I think this is right, but not sure
if(Val==0)
{ DO STUFF;}
else{DO MORE STUFF}
}
而且,我甚至不知道,如果STRCMP部分是正確的,因爲程序崩潰它到達那裏之前。我究竟做錯了什麼?
謝謝你的澄清,是的,主要的()是在實際的碼是否正確。你的建議和@Kaylums一起工作完美,非常有幫助。我試圖製作更簡單的代碼版本,因爲實際代碼非常冗長。 –