| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6103 人关注过本帖
标题:求助,函数声明出现array type has incomplete element type的编译报错
只看楼主 加入收藏
九月飞雪C
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-12-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求助,函数声明出现array type has incomplete element type的编译报错
程序代码:
#include<stdio.h>
#include<string.h>
#define MAXLINE 40
char * s_gets( char * st , int n);
int sort_max_value(struct book str[],int n);
struct book
{
    char title[MAXLINE];
    float value;
};

int main()
{
    struct book library[MAXLINE];
    int maxbook;
    scanf("%d",&maxbook);
    int index;
    for( index = 0 ; index < maxbook ; ++index)
    {    
        scanf("%s",&library[index].title);
        //s_gets( library[index].title, MAXLINE);
        while( getchar() != '\n')
            continue;
        scanf("%f",&library[index].value);
    }
    sort_max_value(library,maxbook);
    printf("highest price: %.1f, %s\n",library[maxbook-1].value,library[maxbook-1].title);
    printf("highest price: %.1f, %s\n",library[0].value,library[0].title);

} 

char * s_gets( char * st, int n)
{
    char * rev_val;
    char * find;
    rev_val = fgets(st,MAXLINE,stdin);
    if(rev_val)
    {    
        find = strchr( st , '\n');
        if(find)
            *find = '\0';
        else
            while( getchar() != '\n')
                continue;
    }
    return rev_val;
}

int sort_max_value( struct book str[],int n)
{
    int i,k;
    float temp_value;
    char temp_ch[MAXLINE];
    for( i = 1 ; i < n ; ++i)
    {
        temp_value = str[i].value;
        strcpy(temp_ch,str[i].title);
        for( k = i ; k > 0 && str[k-1].value > temp_value ;--k)
        {
            str[k].value = str[k-1].value;
            strcpy(str[k].title,str[k-1].title); 
        }
        str[k].value = temp_value;
        strcpy(str[k].title,temp_ch);
    }
}


代码如上,在dev上是没有报错可以正常编译运行,可以一旦到了学校的OJ上就直接编译报错
贴出报错
程序代码:
a.c:5:32: error: array type has incomplete element type

 int sort_max_value(struct book str[MAXLINE],int n);
                                ^
a.c:5:27: warning: ‘struct book’ declared inside parameter list [enabled by default]

 int sort_max_value(struct book str[MAXLINE],int n);
                           ^
a.c:5:27: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
a.c: In function ‘main’:
a.c:20:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[40]’ [-Wformat=]
   scanf("%s",&library[index].title);
   ^
a.c:26:2: error: type of formal parameter 1 is incomplete
  sort_max_value(library,maxbook);
  ^
a.c:26: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/ccO6HnKI.out file, please attach this to your bugreport.

感觉是不同的C版本不一样导致的,但是不知道怎么修改(晕)
搜索更多相关主题的帖子: type str char int library 
2017-12-04 16:47
虫眼
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:10
帖 子:314
专家分:1121
注 册:2017-11-29
收藏
得分:10 
你应该明确声明结构体,不能用struct关键字做形参的名字。
2017-12-04 17:07
liaohs
Rank: 4
等 级:业余侠客
威 望:7
帖 子:61
专家分:292
注 册:2017-11-26
收藏
得分:10 
strict book的声明应该出现在使用之前。
应该移到sort_max_value函数声明之前。

%s后面不应该用&运算
2017-12-04 17:43
九月飞雪C
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-12-4
收藏
得分:0 
感谢,已经解决了,是声明顺序的问题,要把strict book 放在函数声明前面就好了
2017-12-04 18:12
快速回复:求助,函数声明出现array type has incomplete element type的编译报错 ...
数据加载中...
 
   



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

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