首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

一样的程序在codeblock cfree5.0编译结果不同,为什么

2013-10-07 
同样的程序在codeblockcfree5.0编译结果不同,为什么?#include stdio.h#include stdlib.h#includeio.h

同样的程序在codeblock cfree5.0编译结果不同,为什么?

#include <stdio.h>
#include <stdlib.h>
#include  <io.h>
#include  <time.h>
#include  <math.h>

#define  OK     1
#define  ERROR  0
#define  TRUE   1
#define  FASLE  0
#define  MAXVEX 100    /**< 最大顶点数 */

typedef  int  Status;
typedef  int   VertexType;
typedef  int   EdgeType;

/**< 边表节点 */
struct  edgenode;
typedef  struct  edgenode  EdgeNode;
struct  edgenode
{
    int    adjvertex;
    EdgeNode   *next;
};
/**< 顶点节点 */
struct   vertexnode;
typedef    struct   vertexnode    VertexNode;
typedef   VertexNode   AdjList[MAXVEX];
struct   vertexnode
{
    VertexType   data;
    EdgeNode   *header;
};

/**< 图 */
struct   graph;
typedef  struct  graph  *Graph;
struct   graph
{
    int  numvertex,numedge;
    AdjList  adjList;
};

void  CreatGraph(Graph G)
{
    G=(Graph)malloc(sizeof(struct graph));

    int  i,j,k;
    EdgeNode   *E;
    printf("输入顶点数和边数:\n");
    scanf("%d %d",&G->numvertex,&G->numedge);


    for(i=0; i < G->numvertex; i++)
        G->adjList[i].header = NULL;

    for(i=0; i < G->numedge; i++)
    {
        printf("输入边(vi,vj)上的顶点序号:\n");
        scanf("%d  %d",&i,&j); /* 输入边(vi,vj)上的顶点序号 */

        E=(EdgeNode *)malloc(sizeof(EdgeNode));
        E->adjvertex = j;
        E->next=G->adjList[i].header;
        G->adjList[i].header =E;

        E=(EdgeNode *)malloc(sizeof(EdgeNode)); /* 向内存申请空间,生成边表结点 */
E->adjvertex=i;/* 邻接序号为i */
        E->next = G->adjList[j].header;
        G->adjList[j].header =E;

    }

}



codeblock12.11:

D:\CODE\codeblock\adjlist\creatadjlist.c|28|error: array type has incomplete element type|
D:\CODE\codeblock\adjlist\creatadjlist.c|41|warning: type defaults to 'int' in declaration of 'adjList' [-Wimplicit-int]|
D:\CODE\codeblock\adjlist\creatadjlist.c||In function 'CreatGraph':|
D:\CODE\codeblock\adjlist\creatadjlist.c|55|error: subscripted value is neither array nor pointer nor vector|
D:\CODE\codeblock\adjlist\creatadjlist.c|64|error: subscripted value is neither array nor pointer nor vector|
D:\CODE\codeblock\adjlist\creatadjlist.c|65|error: subscripted value is neither array nor pointer nor vector|
D:\CODE\codeblock\adjlist\creatadjlist.c|69|error: subscripted value is neither array nor pointer nor vector|
D:\CODE\codeblock\adjlist\creatadjlist.c|70|error: subscripted value is neither array nor pointer nor vector|
D:\CODE\codeblock\adjlist\creatadjlist.c|48|warning: unused variable 'k' [-Wunused-variable]|
D:\CODE\codeblock\adjlist\main.c||In function 'main':|
D:\CODE\codeblock\adjlist\main.c|7|error: unknown type name 'AdjGraph'|
D:\CODE\codeblock\adjlist\main.c|8|error: 'AdjGraph' undeclared (first use in this function)|
D:\CODE\codeblock\adjlist\main.c|8|note: each undeclared identifier is reported only once for each function it appears in|
D:\CODE\codeblock\adjlist\main.c|8|error: expected ';' before 'malloc'|
D:\CODE\codeblock\adjlist\main.c|9|warning: implicit declaration of function 'CreatAdjGraph' [-Wimplicit-function-declaration]|
||=== Build finished: 9 errors, 3 warnings (0 minutes, 1 seconds) ===|
cfree就可以,到底是什么问题啊!


c typedef


[解决办法]
文件名 
creatadjlist.c 改 creatadjlist.cpp让mingw用g++编译。

或者手工用g++编译。
[解决办法]
用的什么编译器?
你把这两句


typedef    struct   vertexnode    VertexNode;
typedef   VertexNode   AdjList[MAXVEX];

放到结构体定义后面试试,前置声明去掉。

热点排行