Frage

struct FailedTransaction{
    OrderNodePtr order;
    int failureID;
    struct FailedTransaction* next;
    struct FailedTransaction* tail;
};
typedef struct FailedTransaction* FailedTransactionPtr;

struct SuccessfulTransaction{
    OrderNodePtr order;
    struct SuccessfulTransaction* next;
    struct SuccessfulTransaction* tail;
};
typedef struct SuccessfulTransaction* SuccessfulTransactionPtr;

struct FinalReport{
    FailedTransactionPtr failedTransactions;
    SuccessfulTransactionPtr successfulTransactions;
};

struct FinalReport* report = NULL;

This code is declared above main. When accessing

report->successfulTransactions

or

report->failedTransactions

I get undefclared identifier for FailedTransaction and SuccessfulTransaction.

Here is the code that manipulates report

if(report == NULL){
    report = malloc(sizeof(struct FinalReport));
    report->failedTransactions = NULL;
    report->successfulTransactions = NULL;
}
if(outcome){
    if(report->successfulTransactions == NULL){
        report->successfulTransactions = malloc(sizeof(SuccessfulTransaction));
        report->successfulTransactions->order = temp;
        report->successfulTransactions->tail = report->successfulTransactions;
    }else{
        report->successfulTransactions->tail->next = malloc(sizeof(SuccessfulTransaction));
        report->successfulTransactions->tail->next->order = temp;
        report->successfulTransactions->tail = report->successfulTransactions->tail->next;
    }
}else{
    if(report->failedTransactions == NULL){
        report->failedTransactions = malloc(sizeof(FailedTransaction));
        report->failedTransactions->order = temp;
        report->failedTransactions->tail = report->failedTransactions;
    }else{
        report->failedTransactions->tail->next = malloc(sizeof(FailedTransaction));
        report->failedTransactions->tail->next->order = temp;
        report->failedTransactions->tail = report->failedTransactions->tail->next;
    }
    report->failedTransactions->failureID = outcome;
}

The errors occur at the first lines after each if statements and else statements.

This is for an assignment and I have been stuck on this for an hour or so (it is due tomorrow night). Can't figure out why it is happening and I can't find anything online. Any help would be appreciated.

This is the header file that contains OrderNodePtr

#ifndef _CONSUMER_
#define _CONSUMER_

struct OrderNode{
    char title[250];
    int id;
    double cost;
    char category[250];
    struct OrderNode* next;
    struct OrderNode* tail;
};

typedef struct OrderNode* OrderNodePtr;

#endif   
War es hilfreich?

Lösung

Try

sizeof(struct FailedTransaction);

Or, make FailedTransaction a typedef:

struct _FailedTransaction;
typedef struct  _FailedTransaction FailedTransaction;

struct _FailedTransaction {
    OrderNodePtr order;
    int failureID;
    FailedTransaction* next;
    FailedTransaction* tail;
};

Why does C need "struct" keyword and not C++?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top