Почему отображается ошибка: ожидается ';', идентификатор или '(' перед 'структура' ' - PullRequest
0 голосов
/ 09 сентября 2018

Я получаю сообщение об ошибке

CC src / main.c В файле, включенном в src / main.c: 8: 0: src /../ include / connectedlist.h: 4:1: ошибка: ожидается ';', идентификатор или '(' перед 'struct' struct donorNode * getNewDonorNode (); ^ ~~~~~ Makefile: 294: рецепт для цели 'obj / main.o' не выполнен make: *** [obj / main.o] Ошибка 1

См. коды здесь - https://github.com/aman-roy/BloodBank

connectedlist.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

connectedlist.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;
}

1 Ответ

0 голосов
/ 27 сентября 2018

Я вытащил репо: git clone https://github.com/aman-roy/BloodBank.git

тогда я запустил make вот так: make

все скомпилировано нормально, и я смог запустить программу: ./bin/BlodBank

Полагаю, вы пытались скомпилировать только некоторые файлы, а не все.

Так что попробуйте вытащить репо и скомпилировать все, это будет работать.

Если вы просто хотите использовать связанный список, вам необходимо сначала включить файл, содержащий определение в linkedlist.c: include/containers.h

так должно выглядеть так:

#include ../include/containers.h
#include ../include/linkedlist.h
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...