我有以下代碼:需要寫入字符串常量,我該如何解決這個問題?
int main() {
char *sPPhrase[51];
/* Input */
printf("Enter string (max. 50 chars):\n");
fflush(stdout); /* Works around an annoying Eclipse bug that fails to display the output from the printf command */
scanf("%s", *sPPhrase); /* Won't work */
/* More code goes here */
}
的scanf()
命令失敗,我想,是因爲* sPPhrase不可寫的sPPhrase指向一個字符串常量。編譯器沒有任何錯誤的線索。過了一會兒,我需要把這個字符串傳遞給這個函數:
char* reverse(char* sPPhrase[]);
的字符串常量是不可寫的,但我需要通過這個字符*到這個功能。如何重寫我的代碼以使其工作?
並將scanf更改爲scanf(「%s」,sPPhrase); – 2010-01-26 17:39:20
還需要將scanf更新爲scanf(「%s」,sPPhrase) – zebrabox 2010-01-26 17:42:04
那麼我該如何調用函數?'字符* sPReverse =反向(sPPhrase);'生成此錯誤: 「從兼容的指針類型傳遞'反向」的ARG 1」 – Pieter 2010-01-26 18:35:09