tags:

views:

83

answers:

5

I'm having trouble passing a structure array as a parameter of a function

struct Estructure{
 int a;
 int b;
};

and a funtion

Begining(Estructure &s1[])
{
   //modifi the estructure s1
};

and the main would be something like this

int main()
{
  Estructure m[200];
  Begining(m);
};

is this valid?

+1  A: 

No, you need to typedef your struct, and you should pass the array to it; pass by reference does not work in C.

typedef struct Estructure{
 int a;
 int b;
} Estructure_s;

Begining(Estructure_s s1[])
{
   //modify the estructure s1
}

int main()
{
  Estructure_s m[200];
  Begining(m);
}

Alternatively:

struct Estructure{
 int a;
 int b;
};

Begining(struct Estructure *s1)
{
   //modify the estructure s1
}

int main()
{
  struct Estructure m[200];
  Begining(m);
}
WhirlWind
Thanks this solved mi compíler error problem.
maty_nz
A: 

typedef struct { int a; int b;} Estructure;

void Begining(Estructure *svector) { svector[0].a =1; }

renick
That doesn't really answer the question...
WhirlWind
i keep getting the following error:tp1.c:96: error: expected declaration specifiers or ‘...’ before ‘Medico’
maty_nz
Medico being the Estructure
maty_nz
A: 
Begining(struct Estructure s1[])
{
   //modifi the estructure s1
};

int main()
{
  struct Estructure m[200];
  Begining(m);
  return 0;
};
N 1.1
A: 
typedef struct{
 int a;
 int b;
} Estructure;

void Begining(Estructure s1[], int length)
//Begining(Estructure *s1)  //both are same
{
   //modify the estructure s1
};

int main()
{
  Estructure m[200];
  Begining(m, 200);
  return 0;
};

Note: Its better to add length to your function Beginning.

N 1.1
A: 
Michael Dorgan