returning an array of pointers to structures
This is mostely a problem ive made for myself. I have:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLIST 10
struct ipList {
int id;
char name[ 35 ];
char ip[ 15 ];
};
void getList( struct ipList *list[ ] );
struct ipList *makeIP( void );
void printList( struct ipList *list[ ] );
int main( void ) {
struct ipList *theList[ MAXLIST ];
getList( theList );
printList( theList );
return 0;
}
void getList( struct ipList *list[ ] ) {
int i = 0;
while ( i < MAXLIST ) {
list[ i ] = makeIP( );
list[ i ]->id = i;
strcpy( ( list[ i ]->name ), "citibank.co.cx" );
strcpy( ( list[ i ]->ip ), "209.249.147.15" );
i++;
}
}
struct ipList *makeIP( void ) {
struct ipList *temp;
temp = malloc( sizeof( struct ipList ) );
return ( temp );
}
void printList( struct ipList *list[ ] ) {
int i = 0;
while ( i < MAXLIST ) {
printf( "%s - %s\n", ( list[ i ]->name ), ( list[ i ]->ip ) );
i++;
}
}
Which works, however ive been trying to do this without passing parameters to getList( ), instead I've been trying to have getList( ) return the address to an array of pointers to structures. I can make the array, but seem to be unable to have it be returned.