|
60鱼币
下面是代码,几个函数是没问题的,当我在主函数只声明一个Polynominal时都没有问题,但把我主函数里面注释的一句及之后打开后就会报错
报错图片在下面。
大佬求助。
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct pNode
- {
- int codf; // 系数
- int exp; // 指数
- struct pNode *link;
- } PNode;
- typedef struct polynominal
- {
- PNode *head;
- } Polynominal;
- void Init(Polynominal *, int[], int); // 初始化
- void Output(Polynominal *); // 输出
- int main(int argc, char const *argv[])
- {
- Polynominal PS, *P;
- P = &PS;
- int num[6] = {1, 2, 2, 5, 5, 7};
- P = &PS;
- Init(P, num, 3);
- Output(P);
- Polynominal EX, *E;
- int nums[6] = {1, 2, 2, 4, 5, 8};
- // E = &EX;
- // Init(E, nums, 3);
- // Output(E);
- return 0;
- }
- void Init(Polynominal *P, int *num, int length)
- {
- P->head->codf = 0;
- P->head->exp = -1;
- P->head->link = NULL;
- PNode *temp = P->head;
- for (int i = 0; i < length; i++)
- {
- // 创建pnode节点
- PNode *node = (PNode *)malloc(sizeof(PNode));
- node->codf = num[2 * i];
- node->exp = num[2 * i + 1];
- node->link = NULL;
- temp->link = node;
- temp = node;
- }
- }
- void Output(Polynominal *P)
- {
- int flag = 0;
- PNode *nowNode = P->head->link;
- while (nowNode != NULL)
- {
- if (flag == 0)
- {
- if (nowNode->codf == 1)
- {
- printf("x^%d", nowNode->exp);
- }
- else
- {
- printf("%dx^%d", nowNode->codf, nowNode->exp);
- }
- }
- else if (nowNode->codf < 0)
- {
- printf("%dx^%d", nowNode->codf, nowNode->exp);
- }
- else
- {
- if (nowNode->codf == 1)
- {
- printf("+x^%d", nowNode->exp);
- }
- else
- {
- printf("+%dx^%d", nowNode->codf, nowNode->exp);
- }
- }
- nowNode = nowNode->link;
- flag = 1;
- }
- printf("\n");
- }
- */
复制代码
本帖最后由 jhq999 于 2021-10-20 11:08 编辑
结尾怎么加了个半拉注释符号 */
-
- PNode firstnd;//至少有一个实例吧,都是指针怎么行?
- Polynominal PS, *P;
- PS.head=&firstnd;
- P = &PS;
- int num[6] = {1, 2, 2, 5, 5, 7};
- P = &PS;
- Init(P, num, 3);
复制代码
[code]
|
-
最佳答案
查看完整内容
结尾怎么加了个半拉注释符号 */
[code]
|