0

I'm writing C program and running it using Linux VM. My program has one argument - directory name. Normally for arguments I use array (argv[]) and run my compiled program:./programName directoryName. But my task requires run it like follow: ./programName -f directoryName . The second option doesn't work. How I should use it?

  • 1
    You want to handle the `-f`? What have you tried? What specifically do you need help with? – Carcigenicate Sep 05 '20 at 15:07
  • Yes, I have to handle ```-f``` but I'm not sure what changes I have to do in my code in order to use it and pass ```directoryName``` argument. – john mk Sep 05 '20 at 15:13
  • The traditional way to parse command-line options on Unix systems is with `getopt`, and also `getopt_long` and `getopt_long_only`. There are other libraries as well. – Tom Karzes Sep 05 '20 at 15:13
  • `argc` will be `3`; `argv[0]` will point to `"./programName"` (or something along these lines), `argv[1]` will point to `"-f"`; `argv[2]` will point to `"directoryName"`; `argv[3]` will be `NULL` – pmg Sep 05 '20 at 15:18

0 Answers0