Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 仅计算为无效的字符_C_Character - Fatal编程技术网

C 仅计算为无效的字符

C 仅计算为无效的字符,c,character,C,Character,程序崩溃了,但还没有修复。当前,在while循环中输入的每个字符都无效 char get_yes_or_no_character(void) /* This is to purely get the Y or N for options */ { char choice = '\0'; choice = printf("Would you like to use this roll for a game combination? Press Y for yes or N for no

程序崩溃了,但还没有修复。当前,在while循环中输入的每个字符都无效

char get_yes_or_no_character(void)
/*
  This is to purely get the Y or N for options
*/
{
  char choice = '\0';
  choice = printf("Would you like to use this roll for a game combination? Press Y for yes or N for no!\n");
  scanf(" %c", &choice);
  return choice;
}

char choice_input_validation(char choice)
/*
  This makes sure that input validation for the character is correct
*/
{
  while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
  {
    printf("Invalid option, try again\n");
    choice = printf("Would you like to use this roll for a game combination? Press Y for yes or N for no!\n");
    scanf(" %c", &choice);
  }
  return choice;
}
这是它的一段代码

if (roll < 3)
{
  choice = get_yes_or_no_character();
  choice = choice_input_validation(choice);
}
if (choice == 'y' || choice == 'Y')
{
  break;
}
if(滚动<3)
{
选择=获取“是”或“否”字符();
选择=选择\输入\验证(选择);
}
如果(选项='y'| |选项=='y')
{
打破
}
更改行:

scanf(" %c", choice);
致:

scanf
需要将指针作为参数


还可以从以下位置更改
while
条件:

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
致:

您想考虑<代码>选择<代码>无效,如果< <强> > < <强> >前值的<强>任何< /强>。 换行:

scanf(" %c", choice);
致:

scanf
需要将指针作为参数


还可以从以下位置更改
while
条件:

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
致:

您想考虑<代码>选择<代码>无效,如果< <强> > < <强> >前值的<强>任何< /强>。 您使用此代码

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
    {
        printf("Invalid option, try again\n");
        choice = printf("Would you like to use this roll for a game combination? Press Y for yes or N for no!\n");
        scanf(" %c", &choice);
    }
    return choice;
但是,当任何人输入选项Y时,while的条件总是真的,因为它不等于Y。这就是它进入无限循环的原因。

您使用此代码

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N')
    {
        printf("Invalid option, try again\n");
        choice = printf("Would you like to use this roll for a game combination? Press Y for yes or N for no!\n");
        scanf(" %c", &choice);
    }
    return choice;
但是,当任何人输入选项Y时,while的条件总是真的,因为它不等于Y。这就是它进入无限循环的原因。

还有直线

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N') 
可能不会像你想的那样做,因为选择永远不是这四个字符中的一个,所以它的计算结果总是正确的

while (!( choice == 'y' || choice == 'Y' || choice == 'n' || choice == 'N'))
可能是这样的(我自己还没有编译过)。

这行也是这样的

while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N') 
可能不会像你想的那样做,因为选择永远不是这四个字符中的一个,所以它的计算结果总是正确的

while (!( choice == 'y' || choice == 'Y' || choice == 'n' || choice == 'N'))

可能是这样的(我自己还没有编译过)。

scanf(“%c”,choice)-->
scanf(“%c”和&choice)我投票结束这个问题,因为这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。虽然类似的问题可能在这里的主题,这是一个解决的方式不太可能帮助未来的读者。这通常可以通过在发布前确定并仔细检查重现问题所需的最短程序来避免。天哪,这太容易了。。。我讨厌抓不到像那样愚蠢的错误@LPs快速提问,我修复了&choice,但是现在每个输入的字符都无效了,您看到原因了吗?将所有
|
更改为
&&
scanf(“%c”,choice)-->
scanf(“%c”和&choice)我投票结束这个问题,因为这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。虽然类似的问题可能在这里的主题,这是一个解决的方式不太可能帮助未来的读者。这通常可以通过在发布前确定并仔细检查重现问题所需的最短程序来避免。天哪,这太容易了。。。我讨厌抓不到像那样愚蠢的错误@LPs快速问题,我修复了选择(&C),但是现在每个输入的字符都无效了,你看到原因了吗?将所有
|
更改为
&&
@sarahcampolt不客气,很高兴我帮了忙:)如果你的问题解决了,您可以接受一个答案,使您的问题看起来已解决。@sarahcampolt不客气,很高兴我帮了您:)如果您的问题已解决,您可以接受一个答案,使您的问题看起来已解决。