Analyze the code and plug in a) for execution assuming everything is compiled. I
ID: 3672701 • Letter: A
Question
Analyze the code and plug in a) for execution assuming everything is compiled. If Im correct argv[0]=prog2 and argc=11 for part a. Thank you. No need to compile and run
1. Problel: (30 points) pounts Given the following files in a user directory textl.dat, text2.dat, midtermla, progl, prog2, midtermla.c, progl.c, and prog2.c. The executable files are the executable code for the comesponding source programs are shown below. For brevity, the include directives are not shown. Assume that all include files are properly included. Suppose that there are cat, ls, echo, etc. in /bin with the same name. The source code of the programs and the contents of the data files text2.dat WOW texti.dat midtermla.c int main(int argc, char *argvti) int n; n atoi (argv [2] ) ; execvp (argv In], &argvn;]) perror ("Exec Failure"): printf nHELLO n) exit (1) int main(int argc, char argv) if ((argc2) & (argcExplanation / Answer
prog2 3 cat midterm1a echo 4 prog1 echo3 prog2 text2.dat.
In this command, you are trying to execute prog2.
So, the first statement to be printed is WHAT?
Then the argument argv[1] that is, 3 will be converted into integer, and will be stored in n.
execvp function will take the file pointer, and the arguments as input. Here you passed the parameters argv[3] i.e., midterm1a, along with the string from there will be passed to that function.
Now it will start executing the program midterm1a.
Therefore, here n value is argv[2], that is, 4 will be stored into n.
Again one more execpv is being called with the parameters, echo will be called along with the values 3 prog2 text2.dat
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.