KaramJaber
KaramJaber

Reputation: 913

C - Array of pointers to string

How to do in C - array of pointers to string? Because the string is represented as array of chars i tried to do this:(assumes every string is maximum 10 chars and the array size is 100)

char[10]* array[100]; 

but it is wrong

Any suggestion?

Upvotes: 0

Views: 110

Answers (2)

olegarch
olegarch

Reputation: 3891

For static allocation:

char buf[10][100];

For dynamic allocation:

char *buf[10];

And assign thereafter:

buf[5] = strdup("Hello");

Upvotes: 0

abelenky
abelenky

Reputation: 64730

As Adriano said, in C, the main function contains an array of strings:

int main(int argc, char* argv[])
{ [...] }

argv is an array of strings, and is properly declared.
Copy that. (and if you run into problems, ask a specific, detailed question)

Upvotes: 2

Related Questions