赞
踩
编译软件:vc++6.0
程序目的:Understand pointers to your hat size - if you dare
我写的程序:
# include<stdio.h>
# define int bool
# define true 1
# define false 0
int main()
{
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[] =
{164,166,169,172,175,178,181,184,188,191,194,197};
char *psize = *size;
int *pheadsize = headsize;
float cranium = 0.0f;
int your_head = 0;
unsigned int i;
bool hat_found = false;
//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);
your_head = (int)(8.0f*cranium);
i = 0;
if(your_head == *pheadsize)
hat_fount = true;
else
{
//Find head size in the headsize array
for(i = 1;i < sizeof(headsize)/sizeof(*headsize); ++i)
{
if(your_head > *(pheadsize + i - 1) && your_head <= *(pheadsize +i))
{
hat_found = true;
break;
}
}
}
if(hat_found)
{
printf("\nYour hat size is %c %c%c%c\n",
*(psize + 1),
*(psize + 1*sizeof(*size)/sizeof(**size) + i),
(*(psize + 1*sizeof(*size)/sizeof(**size)+i) == ' ') ?' ' : '/',
*(psize + 2*sizeof(*size)/sizeof(**size) + i));
}
//If no hat was found,the head is too small,or too large
else
{
if(your_head < *pheadsize)
printf("\nYou are the proverbial pinhead.No hat for" " you I'm afraid.");
else
printf("\nYou,in technical parlance,are a fathead." " No hat for you,I'm afraid.\n");
}
return 0;
}
运行结果:
--------------------Configuration: hat - Win32 Debug--------------------
Compiling...
hat.c
F:\C\3.c\hat.c(6) : error C2061: syntax error : identifier 'main'
F:\C\3.c\hat.c(6) : error C2059: syntax error : ';'
F:\C\3.c\hat.c(6) : error C2059: syntax error : ')'
执行 cl.exe 时出错.
hat.obj - 1 error(s), 0 warning(s)
请问如何修改??
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。