I have a pointer to a char in a structure that I use to make a linked list. However, the program crashes when attempting to delete the allocated memory for *char member of the structure. Any ideas?
Here is an example:
struct record
{
char *buffer;
rec *next;
};
typedef record *rec;
...
rec = new rec;
rec->buffer = new char[255];
strcpy (rec->buffer,"Hello"
;
delete []rec->buffer; // this is where it crashes. Why?
...
If I allocate memory to a non-structure pointer to char member and delete it, it works with no problems.
Thank you for any help with this.
Here is an example:
struct record
{
char *buffer;
rec *next;
};
typedef record *rec;
...
rec = new rec;
rec->buffer = new char[255];
strcpy (rec->buffer,"Hello"
delete []rec->buffer; // this is where it crashes. Why?
...
If I allocate memory to a non-structure pointer to char member and delete it, it works with no problems.
Thank you for any help with this.