Returning a single server object is not the same as returning 50 server objects. Your createServers() function is not correct.
I have never returned an array from a C function before, so I'm unsure about the syntax, so I'll just give you a different function prototype (which works far better than returning the array because returning the array forces duplication of 50 server objects while the following doesn't):
void createServers(server object[]);
And you call it like this:
1 2
|
server myServers[50];
createServers(myServers);
|
And please use code tags when posting code: [co
de]
//Code goes here.
[/co
de]
EDIT: One more thing: Since arrays don't know their own size, the function createServers() (and any function that receives an array) should also receive the maximum number of elements the array holds. So correcting myself:
void createServers(server object[], int cElements);
And you call it like this:
1 2
|
server myServers[50];
createServers(myServers, _countof(myServers));
|
If your compiler doesn't know what "_countof" is, define it like this:
1 2 3
|
#ifndef _countof
#define _countof(X) (sizeof(X) / sizeof(X[0]))
#endif
|
Finally, make sure the function createServers() never attempts to read or write beyond the array's capacity. In your case, make sure that the variable 'i' in the FOR loop never equals or exceeds cElements.