Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

function that reads a char array

Hi Experts,

I thought I knew this, but I am getting confused now.  I need to return an array of strings to a caller.
How can I do it.  The following code works, but the caller has to know the size.  If I want the function to return any number of items, how can I do it. ( can you please provide example both using strings and char *)
Thanks.

void getArray(char* a[])
{
	a[0] = "one";
	a[1] = "two";
	a[2] = "three";
	a[3] = "four";
        a[4] = "five";
}

int main() 
{
	char * arr[5];

	getArray(arr);

	for( int  i = 0; i < 5; i++ )
	{
		cout << arr[i] << endl;
	}
	getchar();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ambuli

ASKER

Thank you.