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 3:16 ID:2/Slvb9r

>>6
This is an obvious troll (or someone really stupid) so I'm not taking the bait.

>>5
So what you're saying is you know -how many- null delimited c-style strings there are, but not the length of the strings themselves? Well, that's simple enough to solve.

Just loop and copy all the characters, including the null delimeter, into a second array (knowing how large this second array should be beforehand is another issue entirely, you could use a linked-list type structure if you need an expanding array. The vector template in C++ comes in handy here, I'm not sure what C has since I've never bothered learning it.). Initialize a counter variable and for each null character you encounter and pass to the second array increment it by one. Once your counter reaches 'y,' copy the final null character and quit the loop.

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