c语言中没有<stdbool>,输出不了程序,求高人指点!

/* Program 7.10 Understand pointers to your hat size if you dare */
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
char size[3][12] = { /* Hat sizes as characters */
{'6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7'},
{'1', '5', '3', '7', ' ', '1', '1', '3', '1', '5', '3', '7'},
{'2', '8', '4', '8', ' ', '8', '4', '8', '2', '8', '4', '8'}
};

int headsize[12] = /* Values in 1/8 inches */
{164,166,169,172,175,178,181,184,188,191,194,197};

char *psize = *size;
int *pheadsize = headsize;

float cranium = 0.0; /* Head circumference in decimal inches */
int your_head = 0; /* Headsize in whole eighths */
bool hat_found = false; /* Indicates when a hat is found to fit */
bool too_small = false; /* Indicates headsize is too small */

/* Get the circumference of the head */
printf("\nEnter the circumference of your head above your eyebrows"
" in inches as a decimal value: ");
scanf(" %f", &cranium);
/* Convert to whole eighths of an inch */
your_head = (int)(8.0*cranium);
/* Search for a hat size */
for(int i = 0 ; i < 12 ; i++)
{
/* Find head size in the headsize array */
if(your_head > *(pheadsize+i))
continue;

/* If it is the first element and the head size is */
/* more than 1/8 smaller then the head is too small */
/* for a hat */
if((i == 0) && (your_head < (*pheadsize)-1))
{
printf("\nYou are the proverbial pinhead. No hat for"
"you I'm afraid.\n");
too_small = true;
break; /* Exit the loop */
}

/* If head size is more than 1/8 smaller than the current */
/* element in headsize array, take the next element down */
/* as the head size */
if( your_head < *(pheadsize+i)-1)
i--;

printf("\nYour hat size is %c %c%c%c\n",
*(psize + i), /* First row of size */
*(psize + 1*12 + i), /* Second row of size */
(i==4) ?' ' : '/',
*(psize+2*12+i)); /* Third row of size */
hat_found=true;
break;
}
if(!hat_found && !too_small)
printf("\nYou, in technical parlance, are a fathead."
" No hat for you, I'm afraid.\n");
return 0;
}

把那#include<stdbool.h>
改为以下三行.
#define bool int
#define false 0
#define true 1
换符合C99标准的编译器吧,凡是1999年以后出的编译器都行,如vs,gcc.
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-10-14
/*
stdbool.h 

-- Boolean type and values
(substitute for missing C99 standard header)

public-domain implementation from [EMAIL PROTECTED]

implements subclause 7.16 of ISO/IEC 9899:1999 (E)
*/

#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1

/* program is allowed to contain its own definitions, so ... */
#undef bool
#undef true
#undef false

#if __STDC_VERSION__ < 199901
typedef int _Bool
#endif

#define bool _Bool
#define true 1
#define false 0

#endif /* !defined(__bool_true_false_are_defined) */

第2个回答  2013-10-14
bool改int
#include <stdbool.h>这一行不要
相似回答
大家正在搜