gpt4 book ai didi

c - 获取结构/链接列表的错误

转载 作者:太空宇宙 更新时间:2023-11-04 04:48:09 26 4
gpt4 key购买 nike

我收到以下错误:

A1.c:1:2: error: invalid preprocessing directive #inlcude
A1.c:29: error: two or more data types in declaration specifiers
A1.c: In function 'main':
A1.c:30: error: incompatible types in assignment
A1.c: In function 'insert':
A1.c:45: warning: incompatible implicit declaration of built-in function 'printf'
A1.c:54: warning: incompatible implicit declaration of built-in function '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;
}
}

}

最佳答案

第一行 - 它是#include NOT #inlcude

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

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

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

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

关于c - 获取结构/链接列表的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18886542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com