0

In summary

void someVoid(const char* value_){
    const char* value = "SomeValues"; //This is summary for function that retrieves const char* values
    value_ = value;
}

int main(){
    const char* retrievedValue;
    someVoid(retrievedValue);
    
    //retrievedValue -> empty
}

Retrieved value after calling function, stays same as previously initialized

I can't change variable const char* to char* because I'm using function from additional library that retrieves const char* values

void someVoid(char* value_){
    const char* value = "SomeValues";
    value_ = (char*)value;
}

int main(){
    char retrievedValue;
    someVoid(retrievedValue);
    
    //retrievedValue -> empty
}

I tried casting (char*), it didn't work, retrievedValue is still empty

simz
  • 3
  • 2
  • 2
    The question is about C. Why has it been closed as a duplicate of the C++ question? – 273K Aug 06 '22 at 18:05
  • if I understand correctly, you can't change the function signature. `void someVoid(const char* value_)` – dj1986 Aug 06 '22 at 18:10
  • 1
    Your pointer is passed by value (or copy). The caller's parameter will not be modified by your code. – Thomas Matthews Aug 06 '22 at 18:10
  • Solution was combination of 3 posts- https://stackoverflow.com/questions/33263493/modify-const-char-in-c https://stackoverflow.com/questions/14785442/typcasting-a-character-array-to-a-const-char https://stackoverflow.com/questions/15989892/converting-a-const-char-to-an-array – simz Aug 06 '22 at 22:25

0 Answers0