gpt4 book ai didi

c - 如果 "word"然后打印一些东西

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:47 26 4
gpt4 key购买 nike

我想创建一个有趣的程序来展示给我的一个 friend 。不要刻薄,我是初学者,有点问题。问题是我想让程序扫描一个词,如果这个词是我 friend 的名字“Bob”,那么它会打印“noob”,否则它会打印“pro”。

这就是我所做的,但似乎有些东西不起作用。它指出等号 == 有问题。帮助,伙计们。这是我的编码。

#include <stdio.h>

int main()
{
char x;

printf("Enter the noob's name: ");
scanf(" %c", &x);

if (x == "Bob")
printf("noob\n");
else
printf("pro\n");

return 0;
}

最佳答案

像这样尝试:

#include <stdio.h>
#include <string.h>

int main()
{
char x[30];

printf("Enter the noob's name: ");
scanf(" %s",x);

if (strcmp(x,"Bob")==0)
printf("noob\n");
else
printf("pro\n");

return 0;
}

关于c - 如果 "word"然后打印一些东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19692139/

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