问题描述
结构FailedTransaction {
OrderNodePtr秩序;
INT failureID;
结构FailedTransaction *接下来的;
结构FailedTransaction *尾;
};
typedef结构FailedTransaction * FailedTransactionPtr;结构SuccessfulTransaction {
OrderNodePtr秩序;
结构SuccessfulTransaction *接下来的;
结构SuccessfulTransaction *尾;
};
typedef结构SuccessfulTransaction * SuccessfulTransactionPtr;结构FinalReport {
FailedTransactionPtr failedTransactions;
SuccessfulTransactionPtr successfulTransactions;
};结构FinalReport *报告= NULL;
这code为上述主要声明。当访问
报告 - > successfulTransactions
或
报告 - > failedTransactions
我得到FailedTransaction和SuccessfulTransaction undefclared标识符。
下面是code,它操纵报告
如果(报告== NULL){
报告=的malloc(sizeof的(结构FinalReport));
报告 - > failedTransactions = NULL;
报告 - > successfulTransactions = NULL;
}
如果(结果){
如果(报告 - > successfulTransactions == NULL){
报告 - > successfulTransactions =的malloc(sizeof的(SuccessfulTransaction));
报告 - > successfulTransactions->为了=温度;
报告 - > successfulTransactions->尾=报告 - > successfulTransactions;
}其他{
报告 - > successfulTransactions-> tail->接下来=的malloc(sizeof的(SuccessfulTransaction));
报告 - > successfulTransactions-> tail->下一步 - >为了=温度;
报告 - > successfulTransactions->尾=报告 - > successfulTransactions-> tail->接下来,
}
}其他{
如果(报告 - > failedTransactions == NULL){
报告 - > failedTransactions =的malloc(sizeof的(FailedTransaction));
报告 - > failedTransactions->为了=温度;
报告 - > failedTransactions->尾=报告 - > failedTransactions;
}其他{
报告 - > failedTransactions-> tail->接下来=的malloc(sizeof的(FailedTransaction));
报告 - > failedTransactions-> tail->下一步 - >为了=温度;
报告 - > failedTransactions->尾=报告 - > failedTransactions-> tail->接下来,
}
报告 - > failedTransactions-> failureID =结果;
}
每个if语句和else语句后出现的错误在第一线。
这是一个任务,我一直停留在这一个小时左右(这是由于明天晚上)。想不通为什么它正在发生的事情,我不能在网上找到任何东西。任何帮助将是AP preciated。
这是包含OrderNodePtr头文件
的#ifndef _CONSUMER_
#定义_CONSUMER_结构OrderNode {
焦炭标题[250];
INT ID;
双成本;
焦炭类[250];
结构OrderNode *接下来的;
结构OrderNode *尾;
};typedef结构OrderNode * OrderNodePtr;#万一
尝试
的sizeof(结构FailedTransaction);
或者,让 FailedTransaction
A 的typedef
:
结构_FailedTransaction;
typedef结构_FailedTransaction FailedTransaction;结构_FailedTransaction {
OrderNodePtr秩序;
INT failureID;
FailedTransaction *接下来的;
FailedTransaction *尾;
};
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
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++?
这篇关于与结构未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!