Several people have posted the right answer, but they keep deleting it for some reason. You need to cast it to a non-const pointer; free
takes a void*
, not a const void*
:
free((char*)str);
More Related Contents:
- What is the difference between char s[] and char *s?
- What REALLY happens when you don’t free after malloc before program termination?
- How does free know how much to free?
- How do free and malloc work in C?
- Can a const variable be used to declare the size of an array in C?
- Are string literals const?
- Setting variable to NULL after free
- Does free(ptr) where ptr is NULL corrupt memory?
- typedef pointer const weirdness
- constant pointer vs pointer on a constant value [duplicate]
- Constant pointer vs Pointer to constant [duplicate]
- what is the reason for explicitly declaring L or UL for long values
- Shall I prefer constants over defines?
- Variably modified array at file scope
- Should I free memory before exit?
- Difference between char* and const char*?
- Why am I being allowed to use a const qualified variable as an array size in C?
- Should one really set pointers to `NULL` after freeing them?
- Unsigned hexadecimal constant in C?
- const usage with pointers in C
- Confusion regarding modification of const variable using pointers
- Why do I get different results when I dereference a pointer after freeing it?
- Deep Analysis of Const Qualifier in C
- Is the sizeof(enum) == sizeof(int), always?
- C: Correctly freeing memory of a multi-dimensional array
- Is freeing allocated memory needed when exiting a program in C
- Why exactly should I not call free() on variables not allocated by malloc()?
- How are we able to access the pointer after deallocating the memory?
- How to check if a pointer is freed already in C?
- Is it Undefined Behaviour to cast away the constness of a function parameter?