-
free command
i have the following variable
char text1[30]=" ";
char text2[30]=":";
then after putting some values in text1 and text2 i do
strcat(text1,text2);
then i need to clear text1 and text2 i tried the free command but it gave me a segmentation error....what is wrong??
i am using C in linux
-
free() is used to free memory previously allocated with malloc()/calloc() functions.
Code:
text1[0] = '\0'; /* Or text1[0] = 0; */
does the trick. You could also clear all characters with:
Code:
memset(text1, 0, 30); /* 30 is the size of text1[] array. */
-
If you're unsure what a function does, using the man pages is a good idea, for example man free.