Thread: char buf[256]

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    136

    char buf[256]

    hi all
    Code:
       char buf[256] = {0};
       char buf1[256] = {0};
    i am using these two char arrays.
    how can free these buf and buf1 after using these(means to NULL)

    can you please help me

    thank you in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you could do
    memset( buff, 0, sizeof buff );

    But if the next thing you're going to do is something like strcpy() or fgets() to the buffer, then you're just wasting time (and showing a lack of understanding as to what is going on).

    There is however one case I can think of where memset would be appropriate before say strcpy(), but I don't think I've ever seen the appropriate question being asked. Presumably because people who are capable of discovering the problem are also capable of implementing the solution.

    If your use of 'free' is in the memory allocation sense, then you simply return from the function in which they are declared, and then they're gone automatically.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM