Help! Free C memory :(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • casybay
    New Member
    • Oct 2007
    • 35

    Help! Free C memory :(

    Hi all,

    I am working on a program and I have heap corruption errors. After I debug, I found out that the following codes have problem. And I moved these code to another project and debug it. Please see the following:

    Code:
    #include <stdafx.h>
    
    int main()
    {
        char targetFile[] = "target.txt";
    	free(targetFile);
    	return 0;
    }
    The debug message shows "Error 1 error C3861: 'free': identifier not found d:\study\....\a a.cpp 8"

    Could you please tell me how to free memory for 'targetFile' array?
    Thanks a lot!!
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Free is in <stdlib.h>, so you should #include it.

    Comment

    • wildc
      New Member
      • Mar 2008
      • 4

      #3
      Hey buddy
      the argument i.e pointer in the free function could only be the address returned by malloc or calloc not any other pointer.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Plus that stdafx.h looks like Windows code. If so, you should be using the TCHAR mappings.

        Comment

        Working...