Thread: free command

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    36

    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

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    16
    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. */

  3. #3
    UNIX chick
    Join Date
    Mar 2003
    Posts
    92
    If you're unsure what a function does, using the man pages is a good idea, for example man free.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 02:27 PM
  2. Free store vs. heap
    By CondorMan in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2006, 11:41 AM
  3. Write in many command prompts
    By cfriend in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2004, 01:32 AM
  4. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM