【发布时间】:2019-07-04 11:53:33
【问题描述】:
我有一个字符指针:char *sentences;,我是这样读的:
#include <stdio.h>
int main() {
char *sentences;
sentences="We test coders. Give us a try?";
printf("%s", sentences);
return 0;
}
但我想用 c 中的scanf() 函数阅读。
scanf("%[^\n]s",S); 或 scanf("%s",S); 不起作用。
我该怎么做?
【问题讨论】:
-
gets函数很危险,绝对不能使用。现代 C 标准不再支持它。见:stackoverflow.com/questions/1694036/…
标签: c string pointers scanf char-pointer