Implementation of "app.exe -instruction file" notation in C ++

I have a project for my Data Structures class, which is a file compressor that works using binary trees and other things. We are required to "zip" and "unpack" any file using the following commands on the command line:

For compression: compress.exe -zip file.whatever

To decompress: compress.exe -unzip file.zip

We program in C ++ . I am using IDE Code :: Blocks and compiling with GCC on Windows.

My question is: How do you even implement this? !! How can you get your .exe to get these parameters on the command line and then execute them the way you want?

Also, is there anything special in mind if I want this implementation to compile on Linux?

thanks for the help

+1


a source to share


3 answers


Lo logre, I got it!

I now have a basic understanding of how to use the argc and argv [] parameters in the main () function (I've always wondered what they were good for ...). For example, if I put on the command line:

compress.exe -unzip file.zip



Then:

  • argc is initialized to '3' (number of arguments per line)
  • argv [0] == "compressor.exe" (application name)
  • argv [1] == "-unzip"
  • argv [2] == "file.zip"

Greg (not 'Creg', sorry = P) and Bemrose, thank you guys for your help !! ^^

+1


a source


You can look in your programming text for a function signature main

, your program entry point. That's where you will be able to use these command line parameters.

I don’t want to be more detailed than that, because this seems to be the key point of the assignment, and if I ever find myself with you, I’ll expect you to be able to understand this kind of thing when you get the nudge. :)



Good luck!

+9


a source


As I recall, the Single UNIX Specification / POSIX defines getopt in unistd.h to handle argument parsing for you. Although this is a C feature, it should work in C ++ as well.

GNU GLIBC has this in addition to getopt_long (in getopt.h) for extended GNU style support.

+2


a source







All Articles