Help Please!!
I made a struct array, and I'm trying to pass the entire array of that object to another function.

struct Crypt
{
char english;
char code;
int count=0;
};

void main (void)
{
Crypt Key[26];
analyze(key);
}

void analyze(?????????)
{ int i=0;  /*just a sample of the text*/
	while(i!=26)
	{
		key[i].english=(i+65);
		printf("%d%c  ", key[i].count,key[i].english);
		i++;
	}
}

????? I don't know how to set it up or what i should be passing and it's driving me insane.

How about

void analyze( struct Crypt key[] )
{
  ...
}

Although not required, you should pass the size of the array, too:

void analyze ( struct Crypt key[], int size )

This way the function works with different array sizes.

I don't know why people don't consult a book before post something?

commented: STFU. his question is totally valid, and he attempted it before asking. You, need to go learn how to initiialize pointers before you give out more f--ked up programming "advice" -1

^ his question is totally valid here. you, on the other hand, are not.

void main (void)
{
Crypt Key[26];
analyze(key);
}

one small problem you're going to have is that you're capitalizing your variable declaration, but lowercasing the argument.

you also need to consider whether or not you're going to modify the structure you pass to your function. if so, then you need to use the 'address of' operator (&) to pass the structure, and use the dereference operators (->) to assign new values to the pointed elements of the structure.

you also need to consider whether or not you're going to modify the structure you pass to your function. if so, then you need to use the 'address of' operator (&) to pass the structure, and use the dereference operators (->) to assign new values to the pointed elements of the structure.

Nope, sorry.

commented: Such a kewl dude! +1

oops. my bad. i was thinking about a structure of arrays, when he (and you) are clearly talking about an array of structs

but if i rewrite his code can i still pretend I know what I'm talking about? :D

struct Crypt
{
   char english[26];
   char code;
   int count[26];
};
void analyze(struct Crypt[]);

void main (void)
{
   struct Crypt Key;
   analyze(&Key);
}

void analyze(struct Crypt key[])
{ int i=0;  /*just a sample of the text*/
   while(i!=26)
   {
      key->english[i]=(i+65);
      printf("%d%c  ", key->count[i],key->english[i]);
      i++;
   }
}
commented: Using void main? tsk, tsk :P -4
commented: ;) +15

awww. crap man, i didn't even notice his "void main"... i just edited his original code for the relevant parts where he was passing the array.

thats not fair.

:(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.