在IF及其他条件下接收相同的输出,如何解决?
我正在尝试执行以下程序,但是如果其他条件,它会提供相同的输出。在输出中,即使我以周日为价,我也只能获得工作日。
#include <stdio.h>
int main(void)
{
char day;
printf("Enter Day name: \n");
scanf("%c", &day);
if (day =="sunday"){
printf("Holiday");
}
else{
printf("Working day.");
}
return 0;
}
I am trying to execute below program but it give same output, in if else condition. In output I only get Working day only even I give value as sunday.
#include <stdio.h>
int main(void)
{
char day;
printf("Enter Day name: \n");
scanf("%c", &day);
if (day =="sunday"){
printf("Holiday");
}
else{
printf("Working day.");
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该程序无效。
要输入字符串,您需要声明字符数组,而不是类型
char
的对象,其中将存储输入的字符串。例如,要比较字符串,您需要使用标准功能
strcmp
在标题&lt; string.h&gt;
中声明。The program is invalid.
To enter a string you need to declare a character array instead of an object of the type
char
where the entered string will be stored. For exampleTo compare strings you need to use standard function
strcmp
declared in the header<string.h>
.