Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of pointers 3

Status
Not open for further replies.

mattias1975

Programmer
Jul 26, 2004
36
0
0
SE
Hello!
Whats wrong with this?

char *pointer[10];

strcpy(pointer[0], "hello");
printf("%s", pointer[0]);

Thank you
 

you can use a two-dimensional array of course:

Code:
const int max = 10, size = 256;
char strings[max][size+1];
strcpy(strings[0], "hello");
printf("%s", strings[0]);
 
Code:
pointer[0] = "hello";
This is also valid.

It's usefulness on the other hand depends on what you want to do next.

--
 
It's because that the memory space (where "hello" is stored) that pointer[0] points to is not specified.
try this:
Code:
void main()
{
	char *pointer[10];
	pointer[0] = new char [10];
	strcpy(pointer[0], "hello");
	printf("%s", pointer[0]);  
	delete [] pointer[0];
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top