我正在一個項目上工作,我很困惑這部分。將字符串讀入字符數組,然後獲取字符串的大小
我需要從標準輸入讀取單詞並將它們放置在字符數組中,並使用指針數組指向每個單詞,因爲它們將呈鋸齒狀。其中numwords是一個int,表示單詞的數量。
char words[10000];
char *wordp[2000];
問題是我只能使用指針來添加單詞。我不能再使用[]來幫助。
*wordp = words; //set the first pointer to the beginning of the char array.
while (t < numwords){
scanf("%s", *(wordp + t)) //this is the part I dont know
wordp = words + charcounter; //charcounter is the num of chars in the prev word
t++;
}
for(int i = 0;words+i != '\n';i++){
charcounter++;
}
任何幫助將是偉大的我很困惑,當涉及到指針和數組。
'wordp = words'甚至不會編譯。向我們展示您的真實代碼。 – 2013-03-20 22:29:27
我知道這不會編譯多數民衆贊成在這個問題,我完全失去了我不知道如何做到這一點 – 2013-03-20 22:36:27
你有10,000個單詞嗎?或者_really_長串? (你已經宣佈了後者)。下一行聲明瞭2000個指針。 – teppic 2013-03-20 22:38:52