使用结构/链接列表获取错误

时间:2013-09-19 05:06:17

标签: c struct types compiler-errors linked-list

我收到以下错误:

  

A1.c:1:2:错误:预处理指令无效#inlcude
   A1.c:29:错误:声明说明符中的两个或多个数据类型
   A1.c:功能'main':
   A1.c:30:错误:分配中不兼容的类型
   A1.c:在函数'insert'中:
   A1.c:45:警告:内置函数'printf'的不兼容隐式声明
  A1.c:54:警告:内置函数'printf'的不兼容隐式声明

对于以下代码:(请记住,目前很多变量都没有被用作不完整的并需要很多工作,但我无法编译以测试我的代码是否有效或不,显然不是这样)

#inlcude <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXL 100           //max Last name field length
#define MAXR 100           //max Rest field length
#define MAXM 5             //max message-string length e.g., "FIND"
#define MAXI 520           //max input line length

typedef char Last_t[MAXL];
typedef char Rest_t[MAXR];

void insert(char last[],char rest[]);

//DEFFINITION OF OUR NODE or CONTACT
typedef struct NodeTag {
   Last_t     Last;
   Rest_t     Rest;
   struct NodeTag *Link;
} Node;

//DEFINITION OF CONTACT LIST
typedef struct {
   Node *Index[26];
   Node *L;
} ContactList;

//STATIC CONTACT LIST INITIATED
static ContactList con ;

int void main () {
con.Index= NULL;
con.L = NULL;
insert( "Amir", "S");


}

//create a node and insert it to the List con of ContactList
void insert ( char last[], char rest[]) {
 Node *node, *next, *prev;
 node= malloc (sizeof(Node));
 strcpy(node->Last,last);
 strcpy(node->Rest,rest);
 if (con.L == NULL ){
   node->Link=con.L;
   con.L = node ;
  printf("Added %s %s\n",last,rest);
  }

 else {
  Node *current = con.L ;

  while(current->Link !=NULL) {
     if (current->Link == NULL) {
           current->Link = node;
           printf("Added %s %s\n",last,rest);

     }
     current = current->Link;
  }
 }

}

1 个答案:

答案 0 :(得分:0)

第一行 - #include NOT #inlcude

怎么可能是int void main()?它应该是int或void。

con.Index = NULL无效。 Index是一个const指针,NULL是一个void *。同样的原因你不能做Index ++。您无法更改索引的值。

当您纠正第1行时,警告应该消失。

如果您阅读了代码,所有这些都很容易纠正。你试过这样做吗?

相关问题