函数返回C



我是C编程的新手,在我的程序中遇到了以下问题。我在函数(POLYmake)中创建了一个多项式作为链表,我想在变量poly1的主函数中返回这个列表(第二个多项式为poly2)。return语句的语法应该是什么?

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
int sunt;
int dun;
struct node* next;
} Poly;

Poly POLYmake();
int main()
{
Poly poly1, poly2;
printf("Doste to 1o poluwnumo : n");
poly1 = POLYmake();
printf("Doste to 2o poluwnumo : n");
poly2 = POLYmake();
}
Poly POLYmake()
{
Poly *head;
Poly *curr;
head = NULL;
int stop = 1;
int i = 1;
int suntelestis, dunami;
char x;
while(stop != 0)
{
    curr = (Poly*)malloc(sizeof(Poly));
    int y=1;
    printf("Doste to suntelesti tou %dou orou : ",i);
    scanf("%d",&suntelestis);
    curr->sunt = suntelestis;
    printf("Doste ti dunami tou %dou orou : ",i);
    scanf("%d",&dunami);
    curr->dun = dunami;
    curr->next = head;
    head = curr;
    printf("Yparxei kai allos oros tou polywnumou? (Y or N) : ");
    scanf("%s",&x);
    while(y == 1)
    {
        if(x == 'Y')
        {
            y=0;
            i++;                
        }
        else if (x == 'N')
        {
            stop=0;
            y=0;
        }
        else
        {
            printf("Yparxei kai allos oros tou polywnumou? (Y or N) : ");   
            scanf("%s",&x);
        }
    }
}
return ????????? ;
}
Poly *POLYMake()
{
...
    return head;
}

应该做到这一点。

相关内容

  • 没有找到相关文章