本人小白 刚入门C语言 用VS2019。用scanf_s输入两个字符串,运行出错。。求各位大佬解答

#include<stdio.h>
int main()

char a[5],b[5];
scanf_s("%s %s",a,b);
printf("%s %s",a,b);
}运行为什么会访问冲突

第1个回答  2020-04-09
应该改为
#include<stdio.h>
int main()

char a[5],b[5];
scanf_s("%s %s",a,5,b,5);
printf("%s %s",a,b);
输入字符串时要加上字符串的长度
原型为scanf_s("%s",a,length);
length 为字符串长度。
第2个回答  2020-01-24
由于字符数组的大小定义得太小,每个数组中最多只能输入4个字符,所以容易造成数组使用溢出。建议改为50.
#include<stdio.h>
int main()
{ char a[50],b[50];
scanf_s("%s%s",a,b);
printf("%s%s",a,b);
return 0;
}本回答被网友采纳