我的问题非常基本,我想知道如何扫描一组字符,例如一个单词,将该单词归因于一个变量,然后打印它
据我所知,我必须定义我的变量,例如
char word;
然后喜欢
scanf("%c", &word);
但是当我这样做时 printf("\n %c", word)
;它给了我一个奇怪的字符,而不是整个字符组 w + o + r + d
我想我缺少诸如声明数组 idk 之类的东西,xD 有人可以教我吗?
最佳答案
如果您只是像字符数组一样使用 %s
字符串格式化程序:
char word[16];
if (scanf("%15s", word) != 1) /* The correct way to use `scanf()' */
fprintf(stderr, "Error: this is really wierd but possible!\n");
else
fprintf(stdout, "Ok, so the input is: %s\n", word);
关于c - C语言中如何读取一组字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33930343/