繁体   English   中英

为什么从未达到断点?

[英]Why the breakpoint is never reached?

考虑下面的代码:

#include<stdio.h>

/* Makes you guess a number and predicts it.
 */

int main(void)
{
short guess=0;
_Bool first_time="TRUE";
printf("Guess a number from 1 to 100\n");
printf("Lemme guess it\n");
printf("Press n if the guess is wrong, y otherwise\n");
    do
    {
      if (first_time)
      {
        first_time="FALSE";
      }
      else
      {
        printf("Break point"); // This point is never reached while execution
        while (getchar() != '\n')
        ; // Waste the buffer till the newline character
      }
      printf("\nMy guess : %d",++guess); 
      printf("\nAm i right ? ");

    }while( getchar() != 'y' );
return 1;
}

我的直觉是应该在do-while循环的第二次迭代中到达断点。 但这没有发生。

有人可以解释为什么吗?

注意:

编译器:gcc版本4.9.2(Debian 4.9.2-10)

您正在将字符串分配给_Bool类型的类型。 您可能已经收到警告,提示您正在分配一个指向整数类型或类似类型的指针。 _Bool类型应使用0或1。

如果打印first_time的值,则会发现first_time始终为1。请在此处查看_Bool( http://en.cppreference.com/w/c/language/arithmetic_types#Boolean_type )。

您必须包含stdbool.h,并添加使用以下链接:first_time = true;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM