我有以下代码:需要写入字符串常量,我该如何解决这个问题?
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