I have an assignment and it ask me for Re-implement my solution for a Problem (w
ID: 3532698 • Letter: I
Question
I have an assignment and it ask me for
Re-implement my solution for a Problem (with functions
and arrays) using command-line arguments as follows:
FileCrypt -encrypt "hello.txt" "hello.out"
FileCrypt -decrypt "hello.out" "hello.ans"
I have my problem solved but I don't know how to start with the command line ( I don't get this part )
the FileCrypt -encrypt "hello.txt" "hello.out"
FileCrypt -decrypt "hello.out" "hello.ans"
someone please expline it and show an example for me and help me will get 5/5
Explanation / Answer
Command line arguments can be accessed within the main function :
int main(int argc,char *argv[])
In the above statement :
argc is the argument count (no. of command line arguments )
argv[] is a char * array ( a string array ) of all command line arguments
(Remember the program name 'FileCrypt' in this case, is counted as a command line argument as well )
FileCrypt -encrypt "hello.out" "hello.ans"
The above values will automatically be set in your program (i.e, you can directly access those variables from inside your main function)
gcc <program.c> -o FileCrypt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.