char** a;
int num_strings=1;
a=(char**)malloc(num_strings*sizeof(char*));
a[0]=(char*)malloc(strlen("hello word"+1);
a[1]=(char*)malloc(strlen("good bye"+1);
.....
free(a[0]);
free(a[1]);
free(a); John Fill
My mistake. int num_strings=1; should be int num_strings=2; in my code. I've focused my attention on memory allocating.
By the way, sizeof s1 is not too reliable. For example if instead of char s1[] was char* s1 your sizeof would return always 4. John Fill
Right, but since I knew s1 was an array I used sizeof. Why waste processor time with strlen() when you can have the C preprocessor give you the same information for free?
Russ
bobbitts@hotmail.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.