I want to change the value of character array, when I am using like this
char *str;
fun(str);
void fun(char *str) {
str = (char *) ("changed");
}
It is not doing anything and having str as null
whereas in this manner
char *str;
fun(&str);
void fun(char **str) {
*str = (char **) ("changed");
}
It is coming fine. But I have a restriction to have the function definition as void fun(char *str), how to change the value using this usecase
*str = (char **) ("changed");is wrong, don't cast achar *with(char **), the first snippet is also wrong, you are changing the value of a local variable. how to change the value using this usecase: Usingstrcpy:void fun(char *str) { strcpy(str, "changed); }.strmust point to allocated space (an array or viamalloc) with space enough to store "changed"