Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

copy an array in c

Name: Anonymous 2007-03-12 22:30 ID:016HOAcL

I have a function, it accepts a char**, what is the quickest and most efficient way of making a local copy of the array in the function scope?

That is, i have , for example:

void funk(char **x){

char **b;

/*How do i make a separate copy of x to b?*/
}

Take pity on me internets, I'm a noob :) Thanks.

Name: Anonymous 2007-03-13 0:13 ID:2/Slvb9r

Well first you'd have to know the size of the two-dimensional array. That's impossible to know with a two-dimensional array unless explicity specified. Your c-style strings will be null-delimited but there's no way to know how many of those c-style strings there are.

Unless you want to copy that string on the free store, just declare your two-dimensional array on the stack, like so:
char b[x][y]; // assuming you know x and y

Then it's simple. Create a loop that iterates 'x' number of times and use strcpy() to copy the c-style, null-delimited strings (assuming these -are- null-delimited strings).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List