P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

How to return a struct?

I am having difficulty defining the return type in the method 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?

Upvotes: 0

Views: 192

Answers (1)

Doug Currie
Doug Currie

Reputation: 41170

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.

Upvotes: 4

Related Questions