Realloc Invalid Pointer Error
Char * temp = (char *) realloc (SRC, sizeof (char) * 100 );
As shown in the above lineCode. The error occurs because SRC points to a non-null or heap address.
The specific requirements of the realloc function are as follows:
1. src = NULL
2. the SRC pointer must be malloc (), calloc (), or realloc () allocated
Code that causes errors
The error code is generally in the following format:
Char * src = "Hello world! "; // Error code
Or
Char SRC [100]; // error code
The above two methods are used to allocate memory in the stack (if SRC is a local variable) or static area (if SRC is a global variable ). If SRC is passed to realloc, The realloc Invalid Pointer Error will occur.
Solution:
1. Use SRC to display allocated memory with malloc
Char * src = "Hello world! ";// Error code
You can replace it with the following code:
Char * src = (char *) malloc (strlen ("Hello world! "));
Strcpy (SRC, "Hello world! "); // The string. h header file is used.
Char SRC [2, 100];// Error code
You can replace it with the following code:
Char * src = (char *) malloc (sizeof (char) * 100 );
2. Set SRC to null
Char * src = NULL;
This article is original by Ladd. For more information, see the source.
Http://www.cnblogs.com/ladd/archive/2012/07/02/2572112.html
Realloc Invalid Pointer Error
Char * temp = (char *) realloc (SRC, sizeof (char) * 100 );
For example, the above line of code may contain errors in the title. The error occurs because SRC points to a non-null or heap address.
The specific requirements of the realloc function are as follows:
1. src = NULL
2. the SRC pointer must be malloc (), calloc (), or realloc () allocated
Code that causes errors
The error code is generally in the following format:
Char * src = "Hello world! "; // Error code
Or
Char SRC [100]; // error code
The above two methods are used to allocate memory in the stack (if SRC is a local variable) or static area (if SRC is a global variable ). If SRC is passed to realloc, The realloc Invalid Pointer Error will occur.
Solution:
1. Use SRC to display allocated memory with malloc
Char * src = "Hello world! ";// Error code
You can replace it with the following code:
Char * src = (char *) malloc (strlen ("Hello world! "));
Strcpy (SRC, "Hello world! "); // The string. h header file is used.
Char SRC [2, 100];// Error code
You can replace it with the following code:
Char * src = (char *) malloc (sizeof (char) * 100 );
2. Set SRC to null
Char * src = NULL;
This article is original by Ladd. For more information, see the source.
Http://www.cnblogs.com/ladd/archive/2012/07/02/2572112.html