Question

Figure 3- Output 3. Modify your code in MyCommand2 to support accommodate variable variable size a length arguments passed through the rgu array to MyCommand3 c) that: nd3) Your third deliverable is a C program( is defined as follows . The argumentArray char argumentArray NULL. Allocate a place holder for each element in the argumentArray (char*) mall argumentArray: the right size for each argument (based on the user Index] (char*)malloo((strlen (argvtargindex]) +1 input) sizeot (char)) Copy the values typed by the user to the argumentArray(F igure 4). Figure 4-argumentArray populated after running: $MyCommand3 UMass RPI SUNY Harvard - Print the arguments (see example in Figure 5) Note: All labs are due before next weeks lab starts SMyCommand3 UMass RPI SUNY Harvard argumentArray[e]: MyCommand3 argumentArray[1]: UMass argumentArray[2]: RPI argumentArray [3]: SUNY rgumentArray[4]: Harvard MyCommand3 UMass RPI SUNY Harvard Rochester HIT rgumentArray[e]: MyCommand3 argumentArray[1]: UMass argumentArray[2]: RPI rgumentArray[3]: SUNY argumentArray[4]: Harvard argumentArray[5]: Rochester rgumentArray[6]: MIT Figure 5-Output of MyCommand3
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {

    char **argumentArray = (char **) malloc((argc+1) * sizeof(char*));

    int i, j;
    for(i=0; i<argc; i++) {
        argumentArray[i] = (char *) malloc((strlen(argv[i])+1) * sizeof(char));

        strcpy(argumentArray[i], argv[i]);
    }


    for(i=0; i<=argc; i++) {
        printf("%s\n", argumentArray[i]);
    }

}

main.c 1 #include<stdio.h> 2 #include <stdlib.h> #include <string.h> 4 5 int main(int argc, char argvIl) 7 char **argumentArray-(char) malloc((argc+1) sizeof(char; int i, j; 9 10 argunentArray[i] (char *) malloc((strlen(argv[i])+1) sizeof (char)); 12 13 14 15 16 17 18 19 20 21 strcpy (argunentArray[i], argv[i]); printf(%s\n, argumentArray[1]); input /home/a.out Ss RPI SUNY arvard (null)

Hi. please find the answer above.. In case of any doubts, please ask in comments. If the answer helps you, please upvote. I am in great need of upvotes. Thanks!

Add a comment
Know the answer?
Add Answer to:
Figure 3- Output 3. Modify your code in MyCommand2 to support accommodate variable variable size a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT