0

I'm new to C programming and trying to figure out why I'm getting an error trying to pass the char variable into the function

char cmd[100];
getLine(&cmd, &line);

function declaration:

int getLine(char *cmdl, char *str)

Error:

cannot convert char (*)[100] to char* for argument 1 to int getLine(char*, char*)
John
  • 73
  • 1
  • 1
  • 4
  • "the char variable" - nah, the `char [100]` variable. –  Jul 30 '13 at 06:16
  • Also, [obligatory link about pointers vs. arrays.](http://c-faq.com/aryptr/index.html) –  Jul 30 '13 at 06:18

2 Answers2

2

Your functions argument types is a char *. So you don't need to use &cmd. Just using cmd will pass the base address of that array.

So either you call the function like:

getLine(cmd, &line);

or change the function declaration like:

int getLine(char **cmdl, char *str)
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
0

As Midhun MP already said, the Array is already passed as a pointer/reference, so no need to reference it in the function call.

DaMachk
  • 643
  • 4
  • 10