| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 780 人关注过本帖
标题:c语言编译误
只看楼主 加入收藏
moshenglong
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2010-7-8
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:10 
c语言编译误
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
    char size[3] [12] = {
        {'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] =
    {164,166,169,172,175,178,181,184,188,191,194,197};
    float cranium = 0.0;
    int your_head = 0;
    int i = 0;
    bool hat_head = false;
    printf("\nEnter the circumferenec of your head above your eyebrows"
    "in inches as a decimal value:");
    scanf("%f", &cranium);
    your_head = (int) (8.0*cranium);
    for(i = 1; i < 12 ; i++)
    if(your_head > headsize)[i-1] && your_head <= headsize[i])
    {
        hat_head = true;
        break;
    }
    if(your_head == headsize[0])
    {
        i = 0;
        hat_head = true;
    }
    if(hat_head)
        printf("\nYour hat size is %c %c%c%c\n",
    size[0][i], size[1][i], (size[1][i] == ' ') ? ' ' : '/',
    size[2][i]);
    else
    {
        if(your_head < headsize[0])
            printf("\nYour are the proverbial pinhead. No hat for"
        "you I'm afraid.\n");
        else
            printf("\nYour, in technical parlance, are a fathead."
        "No hat for you, I'm afraid.\n");
    }
    return 0;
   
};
怎么用TC和VC都不能编译,都会报错,看了两天了,都没发现问题,麻烦哪位大哥指点一下,谢谢!
搜索更多相关主题的帖子: 编译 c语言 
2010-07-08 08:19
waterstar
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:984
专家分:2810
注 册:2010-2-12
收藏
得分:4 
没找到头文件

冰冻三尺,非一日之寒;士别三日,不足刮目相看!
2010-07-08 11:20
a151937404
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:46
专家分:117
注 册:2010-6-11
收藏
得分:4 
没找到stdbool.h这个头文件
2010-07-08 11:46
rainbow1
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:277
专家分:839
注 册:2010-5-19
收藏
得分:4 
1、   if(your_head > headsize)[i-1] && your_head <= headsize[i])


2、
 }
    return 0;
   
};

把这两个标红的地方删除就行了。LZ还是需要再仔细一点啊!
2010-07-08 12:43
Jade0709
Rank: 2
等 级:论坛游民
帖 子:14
专家分:15
注 册:2010-7-6
收藏
得分:4 
以下是引用rainbow1在2010-7-8 12:43:38的发言:

1、   if(your_head > headsize) && your_head <= headsize)


2、
 }
    return 0;
   
};

把这两个标红的地方删除就行了。LZ还是需要再仔细一点啊!
正解,然后去掉#include <stdbool.h>
2010-07-09 10:31
moshenglong
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2010-7-8
收藏
得分:0 
改了还是不行,现在是这样报错:Unable to open include file 'STDBOOL.H'
2010-07-09 18:28
moshenglong
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2010-7-8
收藏
得分:0 
请问一下stdbool.h头文件要怎么样才能找到
2010-07-09 18:29
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:4 
回复 7楼 moshenglong
用写的吧。
/* 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) */
2010-07-09 18:42
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:0 
下标表达式,形如p[i],等价于*(p+i),其中+是指针加法,数值上相当于+ sizeof(*p) * i。“多维”的下标表达式如p[i][j],由结合性等价于(p[i])[j],即*(p[i]+j),也就是*(*(p+i)+j)。[]和一元*操作符的操作数要求为指针类型,可以是数组名,但不能是int。
LZ的函数fun(int *)中,p[i]或p[j]得到一个int而不是数组或指针,p[i][j]或p[j][i]这样的表达式是非法的。
LZ问题的解决方案:fun函数头改为void fun(int (*p)[3])或void fun(int p[][3]);另外,main里面的int *p=a;改为int (*p)[3]=a;。
注:
1.
int(*)[3]是指向int[3]这个数组类型的指针的类型,int(*p)[3]是这种类型的一个名称为p的对象。
2.
C中没有多维数组,所谓多维数组,是指数组的数组,存储器中不保存各维的长度。因此多维数组作为函数参数传递时只有第一维可以省略(可以退化为对应的指针),因为数组不保存计算下标的必要信息,除了第一维以外的剩余长度必须在编译时确定,以进行下标计算。
====
2010-07-09 18:50
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:0 
程序代码:
#include <stdio.h>
int main(void)
{
    char size[3] [12] = {
        {'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] =
    {164,166,169,172,175,178,181,184,188,191,194,197};
    float cranium = 0.0;
    int your_head = 0;
    int i = 0;
    bool hat_head = false;
    printf("\nEnter the circumferenec of your head above your eyebrows"
    "in inches as a decimal value:");
    scanf("%f", &cranium);
    your_head = (int) (8.0*cranium);
    for(i = 1; i < 12 ; i++)
    if(your_head > headsize[i-1] && your_head <= headsize[i])
    {
        hat_head = true;
        break;
    }
    if(your_head == headsize[0])
    {
        i = 0;
        hat_head = true;
    }
    if(hat_head)
        printf("\nYour hat size is %c %c%c%c\n",
    size[0][i], size[1][i], (size[1][i] == ' ') ? ' ' : '/',
    size[2][i]);
    else
    {
        if(your_head < headsize[0])
            printf("\nYour are the proverbial pinhead. No hat for"
        "you I'm afraid.\n");
        else
            printf("\nYour, in technical parlance, are a fathead."
        "No hat for you, I'm afraid.\n");
    }
    return 0;

 
}
这会你试试。
2010-07-09 18:59
快速回复:c语言编译误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014538 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved