我是C语言的新手,当尝试在NetBeans上构建此应用程序时,编译该函数时显然没有错误。但是,当用户输入姓名和性别时,应用程序通常会输入IF
,ELSE IF
和ELSE
,但是当用户输入IF
和ELSE IF
时,用户名不会出现在printf()方法中。
#include <stdio.h>
#include <stdlib.h>
ex19(){
char name[100];
char genre;
printf("Enter your name: ");
scanf("%s",&name);
printf("Enter your genre: ");
scanf("%s",&genre);
if (genre == 'M'){
printf("%s you are a BOY",name);
}
else if (genre == 'F'){
printf("%s is GIRL",name);
}
else {
printf("INVALID GENRE");
}
}
main(){
ex19();
}
此算法会出什么问题?对不起,很抱歉,我是C语言编程的新手,我冒着学习这种语言的风险,而无需看书或观看视频课程。现在,我之所以表现不错,是因为我以前对Java,JavaScript,PHP和C语言编程有所了解。但是无论如何,这段代码中发生了什么?