gpt4 book ai didi

c - 为什么它在 ‘;’ 之前显示错误 : expected ‘(’ , 标识符或 ‘struct’

转载 作者:行者123 更新时间:2023-11-30 21:48:14 25 4
gpt4 key购买 nike

我收到一个错误

CC src/main.c In file included from src/main.c:8:0: src/../include/linkedlist.h:4:1: error: expected ‘;’, identifier or ‘(’ before ‘struct’ struct donorNode* getNewDonorNode(); ^~~~~~ Makefile:294: recipe for target 'obj/main.o' failed make: *** [obj/main.o] Error 1



在此处查看代码 - https://github.com/aman-roy/BloodBank

链接列表.h
#ifndef LINKEDLIST_H_
#define LINKEDLIST_H_

struct donorNode* getNewDonorNode();
struct acceptorNode * getNewAcceptorNode();

struct donorBox* donorDBtoLL();
struct acceptorBox* acceptorDBtoLL();

void distroyAcceptor(struct acceptorNode *);
void distroyDonor(struct donorNode *);

struct donorNode * insertAtTopDonor(struct donorNode *, struct donorNode *);
struct acceptorNode * insertAtTopAcceptor(struct acceptorNode *, struct acceptorNode *);

#endif

链表.c
#include <stdlib.h>
#include <stdio.h>

#include "../include/linkedlist.h"
#include "../include/containers.h"
#include "../include/utilities.h"
#include "../include/color.h"

struct donorNode * getNewDonorNode()
{
struct donorNode *temp = (struct donorNode *)malloc(sizeof(struct donorNode));
temp->next = NULL;
return temp;
}

struct acceptorNode * getNewAcceptorNode()
{
struct acceptorNode *temp = (struct acceptorNode *)malloc(sizeof(struct acceptorNode));
temp->next = NULL;
return temp;
}


struct donorBox* donorDBtoLL()
{
FILE *fp = loadFile('d');
if (!fp)
return NULL;
struct donorNode *temp = getNewDonorNode();
struct donorBox *box = (struct donorBox *)malloc(sizeof(struct donorBox));
if(fread(&temp->data,sizeof(temp->data),1,fp))
{
int count = 0;
struct donorNode *head = NULL;
struct donorNode *front = NULL;
rewind(fp);

while(fread(&temp->data,sizeof(temp->data),1,fp))
{
if (head == NULL)
{
head = temp;
front = head;
temp = getNewDonorNode();
count++;
continue;
}
head->next = temp;
head = temp;
count++;
temp = getNewDonorNode();
}
free(temp);
fclose(fp);

box->head = front;
box->count = count;
}
else
{
box->head = NULL;
box->count = 0;
free(temp);
printf(TD_BOLD TC_RED TD_UNDERLINE"\t\t\t\tNO DATA AVAILABLE!\n");
}
return box;
}



struct acceptorBox *acceptorDBtoLL()
{
FILE *fp = loadFile('a');
if (!fp)
return NULL;
struct acceptorNode *temp = getNewAcceptorNode();
struct acceptorBox *box = (struct acceptorBox *)malloc(sizeof(struct acceptorBox));
if(fread(&temp->data,sizeof(temp->data),1,fp))
{
int count = 0;
struct acceptorNode *head = NULL;
struct acceptorNode *front = NULL;
rewind(fp);

while(fread(&temp->data,sizeof(temp->data),1,fp))
{
if (head == NULL)
{
head = temp;
front = head;
temp = getNewAcceptorNode();
count++;
continue;
}
head->next = temp;
head = temp;
count++;
temp = getNewAcceptorNode();
}
free(temp);
fclose(fp);

box->head = front;
box->count = count;
}
else
{
box->head = NULL;
box->count = 0;
free(temp);
printf(TD_BOLD TC_RED TD_UNDERLINE"\t\t\t\tNO DATA AVAILABLE!\n");
sleep(2);
}
return box;
}

void distroyAcceptor(struct acceptorNode *head)
{
if (head == NULL)
{
return;
}
distroyAcceptor(head->next);
free(head);
}

void distroyDonor(struct donorNode *head)
{
if (head == NULL)
{
return;
}
distroyDonor(head->next);
free(head);
}

struct donorNode * insertAtTopDonor(struct donorNode * current, struct donorNode * head)
{
struct donorNode *temp = (struct donorNode *)malloc(sizeof(struct donorNode));
temp->data = head->data;

if (current == NULL)
{
current = temp;
current->next = NULL;
}
else
{
temp->next = current;
current = temp;
}
return current;
}

struct acceptorNode * insertAtTopAcceptor(struct acceptorNode * current, struct acceptorNode * head)
{
struct acceptorNode *temp = (struct acceptorNode *)malloc(sizeof(struct acceptorNode));
temp->data = head->data;

if (current == NULL)
{
current = temp;
current->next = NULL;
}
else
{
temp->next = current;
current = temp;
}
return current;
}

最佳答案

我拉了 repo :git clone https://github.com/aman-roy/BloodBank.git
然后我像这样启动了:make
一切编译正常,我能够启动程序:./bin/BlodBank
我相信您尝试仅使用一些文件而不是所有文件进行编译。

因此,尝试提取 repo 并全部编译,它会起作用。

如果您只想使用linkedList,那么您需要首先包含包含linkedlist.c 中定义的文件。 : include/containers.h
所以它应该是这样的:

#include ../include/containers.h
#include ../include/linkedlist.h

关于c - 为什么它在 ‘;’ 之前显示错误 : expected ‘(’ , 标识符或 ‘struct’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52245497/

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