我真的不知道我对此做错了什么。每次我编译它,在第四个用户输入时,它只是停止并显示返回的"进程"东西。
#include <stdio.h>
#include <conio.h>
int main() {
char firstname[15], class, swordch0c1, swordch0c2;
int health, healthtot, armor, armortot;
printf("Hello there! Could I have your first name?\n>");
scanf("%s", firstname);
printf("\n---------------------The Legend of %s---------------------", firstname);
printf("\nPress Enter to continue.");
getch();
printf("\n\n\nYou are %s, a(n): \nA.Swordsman\nB.Assassin\nC.Archer\nD.Mage\n>", firstname);
scanf(" %c", &class);
/*swordsman story starts here*/
if (class=='a' || class=='A')
{
printf("\n\nThere you stand, at your boring everyday post.\nWhen you joined the army, you thought it would be more exciting than this.\nJust then, you see your general walking towards you.");
printf("\n\nYou quickly improve your posture. \"Soldier, I have an opportunity for you\"\nA.\"Really? What is it?\"\nB.\"I'm not interested\"\n>");
scanf(" %c", &swordch0c1);
if (swordch0c1=='b'||swordch0c1=='B')
{
printf("\n\"But... I didn't even tell you what it was. Okay, suit yourself\" You are DOOMED to a life of boredom.\n\n\n\n\n");
}
if (swordch0c1=='a'||swordch0c1=='A')
{
printf("\n\n\n\"Well, you see, there's this dragon. He's been causing big problems.\nHe's destroyed villages, harrassed the priests on the mountain,\n");
... 编辑:它允许我输入第四个输入。点击进入后,它显示进程返回的内容。
答案 0 :(得分:0)
这条线几乎肯定是问题所在:
scanf(" %c", &swordch0c1);
您要求读取单个字符,但要实际输入字符,您必须输入两个字符: A 输入。此scanf
来电将会读取'A'
,下一个scanf
来电将会读取'\n'
( Enter )键,该键仍在输入缓冲区。
我建议将fgets()
用于所有用户输入。处理这种方式要容易得多,因为它与用户实际输入输入的方式相匹配(文本行加上 Enter )。