Only use free() when you have assinged memory to a pointer by calling malloc() or calloc(). And that's not what you are doing in your example. So free() won't work in your case and will generate segmentation faults.
A segmentation fault occurs when a program accesses (or free's) memory it should access (or free).
What do you mean by "clearing" text1 and text2:
- Just make the strings empty?
Then just do:
Code:
text[0] = '\0';
text[0] = '\0';
- Make them disappear from memory? Just don't:
If they are global variables (declared outside any function) you just cannot. If they are declared inside a function, they will be free when that function returns.