I have a function that will pass a string and manipulate. in the function call i am passing the string as such like myfunc ("hello");
In the function definition i have
myfunc (char *array)
{
xxxx
};
The program is working fine, but it throws a warning “pointer targets in passing argument 1 of ‘myfunc’ differ in signedness”.
How to rectify this problem?
Strings are actually arrays of constant characters. That is, the type of
"hello"isconst char[6].What this means is you cannot modify it. However, due to a silly conversion in C++, the array (in string literal form) can be implicitly converted to a non-const pointer to the first element. This is misleading, and dangerous. (Indeed, a const-stripping implicit conversion doesn’t exist anywhere else.)
You should make sure you have a modifiable buffer instead: