vs2022版本,scanf_s函数使用的时候后要在取地址后面加上数组的长度,不然会报错。不知其所以然,求大佬解惑。
#include<stdio.h>
int main()
{
int i = 0;
char password[20] = { 0 };
for (i = 0; i < 3; i++)
{
scanf_s("%s", password,20);//password 后要加上数组的长度不然会报错
if (strcmp(password , "123456") == 0)
{
printf("密码正确");
break;
}
else
{
printf("密码错误\n");
}
}
if (i == 3)
{
printf("三次密码错误,请退出程序");//这个if语句要在for循环外面不然无法的到i == 3
}
return 0;
}