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

标签 c

#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/

相关文章:

C - 如何在 linux 中使用 API 库

c - "locks"在保护临界区的程序中是如何工作的?

c - getchar_unlocked() 如何工作?

c - 如何在C宏中区分常量字符串和char *

c - ISO C99 printf ("%Nd"的前导零默认行为)?

java - 为什么 C 和 C++ IDE 工具支持落后于可用于托管平台的工具?

C指针-Segment错误的解决办法是什么

c - 获取 "Message from debugger: Error 1"- 对于简单项目(在 Xcode 11.0 11A420a 中)

c++ - C/C++。库相对于组合目标文件的优势

将 double 的 2 列 .txt 转换为 2 个数组并读取它们