1
我在C中遇到了scanf
问题。在阅读其他关于如何修复scanf
问题的Stackoverflow帖子之后,我现在知道不建议使用scanf
,但我必须将它用于作业分配。我正在尝试根据缓冲区大小来存储具有最大大小的3个字符串值。当我编译并运行这个程序时,我输入值255 255 255
,这就是打印的内容。用scanf存储字符串的问题
1:
2:
3: 255
这里是节目源:
#include <stdio.h>
int main(){
char first[8] = "", second[3] = "", third[3] = "";
scanf("%8s %3s %3s", first, second, third);
printf("1: %s\n2: %s\n3: %s", first, second, third);
}
你知道字符串是如何用C表示的吗? –
'char first [9] =“”,second [4] =“”,third [4] =“”;' – BLUEPIXY
@EugeneSh。是的,作为一组字符。 – T94j0