Home > Software engineering >  passing command line arguments by reference to a function
passing command line arguments by reference to a function

Time:02-14

I want to process command line parameters in seperate function but couldnt pass them. What is the right declaration and definition? And any resource about passing parameters, writing function definition/declaration?

I will use getopt() function in cmd_line() function.

...
...
void cmd_line(*int, *char[]);

int main(int argc, char *argv[]){
    cmd_line(&argc, argv);
    return 0;
}

void cmd_line(int *argc, char *argv[]){
...
...
}

CodePudding user response:

Tried to find a duplicate, but did not find any in this context. To make it searchable, here is the relevant error:

main.c:1:15: error: expected declaration specifiers or ‘...’ before ‘*’ token
    1 | void cmd_line(*int, *char[]);
      |               ^
main.c:1:21: error: expected declaration specifiers or ‘...’ before ‘*’ token
    1 | void cmd_line(*int, *char[]);
      | 

The problem is that

void cmd_line(*int, *char[]);

should be

void cmd_line(int*, char*[]);
  •  Tags:  
  • c
  • Related