gpt4 book ai didi

c - (C程序设计)用户名和密码识别

转载 作者:太空宇宙 更新时间:2023-11-04 01:09:35 24 4
gpt4 key购买 nike

为什么我得到 format '%s' expects argument of type 'char*'?我应该如何解决这个问题?

这是我的代码:

char UserName[] = "iluvcake";
scanf("%s", &UserName);
printf("Please enter your password: \n");
char PassWord[] = "Chocolate";
scanf("%s", &PassWord);
//if...else statement to test if the input is the correct username.
if (UserName == "iluvcake")
{
if (PassWord == "Chocolate"){
printf("Welcome!\n");
}
}else
{
printf("The user name or password you entered is invalid.\n");
}

最佳答案

&UserName 是指向 char 数组(即 char**)的指针。你应该使用

scanf( "%s", UserName );

关于c - (C程序设计)用户名和密码识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15790621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com