gpt4 book ai didi

C语言关于输入输出的printf函数的类型完全相同,但是为什么我看不到输出?

转载 作者:行者123 更新时间:2023-11-30 20:18:43 26 4
gpt4 key购买 nike

#include<stdio.h>

int main(void)
{

char name[40];
scanf("%s",name);

if(name == "yes")
{
printf("%s",name);
}

return 0
}

最佳答案

您需要使用strcmp进行字符串比较。

替换

if(name == "yes")

if(strcmp(name,"yes") == 0)
<小时/>

strcmp 返回

  1. 0 if both strings are identical (equal)

  2. Negative value if the ASCII value of first unmatched character is less than second.

  3. Positive value if the ASCII value of first unmatched character is greater than second.

关于C语言关于输入输出的printf函数的类型完全相同,但是为什么我看不到输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53103571/

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