Disclaimer: I usually do not program in C, so my examples can have any syntax, but I hope that the ideas I'm trying to express are clear.
If “emptying” means “containing an empty string,” you can simply set the first element of the array to zero, which effectively forces the array to contain the empry string:
members[0] = 0;
If “emptying” means “freeing up used memory”, you should not use a fixed char array in the first place. Rather, you should define a pointer to char, and then do malloc / free (or a string assignment) as needed.
An example of using only static lines:
char* emptyString=""; char* members; //Set string value members = "old value"; //Empty string value member = emptyString //Will return just "new" strcat(members,"new");
Konamiman Oct 13 '09 at 11:33 2009-10-13 11:33
source share