-2

I´m trying to copy a string that is in the comand line in argv to "op"

This is the function in C that i have been trying to fix and just can´t. I know it´s something pretty basic but it´s going over my head:

  int main(int argc, char* argv[])
{
   char op[90];
   strcpy(op,*argv[1]);
   printf("\n %s",op);
   return 0;
}
EduDY
  • 1
  • 1

1 Answers1

1

You don't need to specify the pointer sign when using strcpy(). Change:

strcpy(op, *argv[1]);

into:

strcpy(op, argv[1]);

But still you get segfault if no argument is passed. You should create a condition to check if argc != 1, if it's true then instantly stop the program before anything unusual happens.

Rohan Bari
  • 7,482
  • 3
  • 14
  • 34