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:
Anonymous2007-03-15 18:11 ID:acmPTe2g
Answer to what?
Name:
Anonymous2007-03-16 7:15 ID:cZZ6uzeL
It's kind of pointless arguing about null-terminated strings in C. Want to use the standard libraries? You don't really have a choice _but_ to use them. Don't want null-terminated strings? Roll your own string API, and be prepared to not be able to pass your custom strings to the standard library system functions which expect them.
Pointer to the array is too short to read SICP and achieved Satori PROGRAMMING IS ALL YOU NEED OTHERWISE YOU ARE A few other alternatives but none are all that mature yet From what I gather so what should I call you Kris reading from my socialist state I said a buggy!
Name:
Anonymous2010-12-17 1:29
Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?
If you answered "Yes" to all of the above questions, then GNAA(GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
Name:
Anonymous2012-05-28 23:57
// assuming x is a null terminated array of null terminated strings
// untested
void funk(char **x) {
// calculate length of x
size_t len;
for (len = 0; x[len]; ++len);
// allocate copy
char **copy = malloc((len + 1) * sizeof(*x));
// copy over strings
for (size_t i = 0; i < len; ++i) {
copy[i] = malloc(strlen(x[i]));
strcpy(copy[i], x[i]);
}
// add null terminator
copy[len] = 0;
}