1. Homepage
  2. Exam
  3. COMP2017/9017 System Programming - Sample Exam - Q6 Argument Set

COMP2017/9017 System Programming - Sample Exam - Q6 Argument Set

This question has been solved
Engage in a Conversation

Question 6 (Programming) (15 marks)


CourseNana.COM

Write a C function CourseNana.COM

int best argset(int n, int *argc, char ***argv) CourseNana.COM

best argset function returns the index of one argument set with the highest number of characters. An CourseNana.COM

array of arguments is defined in the same memory format as the C main function int argc, char **argv, where argc is a single integer representing the number of arguments and argv is the array of C strings. This is known as the argument set. CourseNana.COM

  CourseNana.COM

best argset function accepts an array of argument sets, where n is the number of argument sets, argc CourseNana.COM

is an array of integers, argv is an array of an array of C strings. The argument set with the highest number of characters has an index from the input. This index is the return value of the function. CourseNana.COM

  CourseNana.COM

On success, the index of the argument set with the highest number of characters is returned. If there is CourseNana.COM

more than one argument set discovered to have the highest, only one is returned and it can be any. -1 is returned if any parameter is NULL, or n is less than or equal to zero. CourseNana.COM

  CourseNana.COM

Example of input data and return value: CourseNana.COM

index    argc[index]       argv[index][0] argv[index][1]              argv[index][2] CourseNana.COM

0          3                      ”abc”                ”def”                            ”ghi” CourseNana.COM

1          1                      ”ruck rover” CourseNana.COM

2          3                      ”./a.out”           ”launch”                       ”5” CourseNana.COM

Returns 2 CourseNana.COM

  CourseNana.COM

The following function may be useful: CourseNana.COM

size t strlen(const char *str); CourseNana.COM

  CourseNana.COM

The function strlen() calculates the length of the string pointed to by str, excluding the terminating null byte. CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
System Programming代写,C Language代写,Memory代写,Pointer代写,System Programming代编,C Language代编,Memory代编,Pointer代编,System Programming代考,C Language代考,Memory代考,Pointer代考,System Programminghelp,C Languagehelp,Memoryhelp,Pointerhelp,System Programming作业代写,C Language作业代写,Memory作业代写,Pointer作业代写,System Programming编程代写,C Language编程代写,Memory编程代写,Pointer编程代写,System Programmingprogramming help,C Languageprogramming help,Memoryprogramming help,Pointerprogramming help,System Programmingassignment help,C Languageassignment help,Memoryassignment help,Pointerassignment help,System Programmingsolution,C Languagesolution,Memorysolution,Pointersolution,