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;
此代码在main之上声明。访问时
report->successfulTransactions
或
report->failedTransactions
我获得了FailedTransaction和SuccessfulTransaction的未声明标识符。
以下是操纵报告的代码
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;
}
错误发生在每个if语句和else语句之后的第一行。
这是一项任务,我已经坚持了一个小时左右(明天晚上到期)。无法弄清楚它为什么会发生,我在网上找不到任何东西。任何帮助将不胜感激。
这是包含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
答案 0 :(得分:3)
尝试
sizeof(struct FailedTransaction);
或者,将FailedTransaction
设为typedef
:
struct _FailedTransaction;
typedef struct _FailedTransaction FailedTransaction;
struct _FailedTransaction {
OrderNodePtr order;
int failureID;
FailedTransaction* next;
FailedTransaction* tail;
};