函数返回链表 - C

时间:2015-11-06 22:36:04

标签: c linked-list

我是C编程的新手,我的程序中存在以下问题。我在函数(POLYmake)中创建一个多项式作为链表,我想在变量poly1(和第二个多项式的poly2)的main函数中返回此列表。 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 ????????? ;
}

1 个答案:

答案 0 :(得分:0)

Poly *POLYMake()
{

...
    return head;
}

应该这样做。