cannot convert parameter

cpp file
1
2
char input[10];
update_input(&input);


header file
void update_input(char * input);

when i do the above i get the error "cannot convert parameter 1 from 'char (*)[10]' to 'char *'", the function update_input is supposed to update the "input" variable, does anyone know where am i going wrong?
Last edited on
That's beucase you are passing it a char* [10], or a pointer to a char[10]. Just passing input by itself; the array will decay to a pointer automatically.
char input[10]; is an array of characters
update_input(char * input) Takes a pointer to a character.
update_input(&input) passes the address of an array of characters. An array is almost identical to a pointer, so you need this function to take a pointer to a pointer if you want to pass in &input.

In header file, change the line to void update_input(char ** input);, which is a pointer to a pointer(or array)

Edit: char input[10]; input is like a pointer to a char, input is the memory address of the first char of the array, you could also change the second line of the cpp file to update_input(input). This is passing in the memory address of a char required by void update_input(char * input);
Last edited on
Topic archived. No new replies allowed.