开发者

How to return a struct?

I am having difficulty defining the return type in the me开发者_Go百科thod signature properly. The problem is

list* GetPrimeNumbers()

struct dynamicArray{
   int val;
   struct dynamicArray * next;
};

typedef struct dynamicArray list;

int PrimeFactor()
{
    int sum = 0;
    list * primeNumbers;
    primeNumbers = GetPrimeNumbers();
    return sum;
}

list* GetPrimeNumbers()
{
    int max = 100;

    list * current, * head;
    head = NULL;

    for(int i = 2; i < max; i++)
    {
     //..implmenetation
    }    
    return current;
}

I have tried several return types, but nothing has worked. I am a beginner level C programmer. What needs to be there?


Either you need a header file with the typedef and prototype for GetPrimeNumbers, or you need to swap the functions GetPrimeNumbers and PrimeFactor in the file.

The way you presented the code, GetPrimeNumbers has no declaration in place when PrimeFactor is compiled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜