Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struct has no member named

My program contains a structure containing two array members. I've called the structure to a void function within function parameters.

structure definition:

struct caketime
{
    double baking_time [4]={20,75,40,30};
    double prepare_time[4]={30,40,25,60};
};

The void function:

void prepareorder(struct caketime p) {

int i=0;
    for (i=0;i<LIMIT;i++)
    {
        if(p.prepare_time[i]==25)
            printf("Choclate");
        else if (p.prepare_time[i]==30)
            printf("Sponge Cake");
        else if (p.prepare_time[i]==45)
            printf("Meringue");
        else if (p.baking_time[i]==60)
            printf("Red_velvet");
    }
}

When I compile this program, I get the errors described below:

In function 'prepareorder': error: 'struct caketime' has no member named 'prepare_time'
error: 'struct caketime' has no member named 'baking_time'

What seems to be the problem over here?

like image 994
AJ J Avatar asked May 28 '13 18:05

AJ J


1 Answers

Try,

struct caketime
{
   double baking_time[4];
   double prepare_time[4];  
};

instead of,

struct caketime
{
   double baking_time [4]={20,75,40,30};
   double prepare_time[4]={30,40,25,60};
};

You should not initialize the array elements inside the structure.

like image 168
Deepu Avatar answered Oct 13 '22 13:10

Deepu