COMP1511 25T1 Prac Exam

Time allowed: 3 hours and 10 minutes (10 minutes reading time, 3 hours working time)

Total number of questions: 11

Total number of marks: 100

Questions are NOT of equal value

The distribution of marks is as follows:

Attempt all questions

You should keep this paper confidential. Sharing it, DURING or AFTER the exam is prohibited.


Paper Information

Exam Condition Summary

Deliberate violation of these exam conditions will be referred to Student Integrity Unit as serious misconduct, which may result in penalties up to and including a mark of 0 in COMP1511 and exclusion from UNSW.

Exam Hurdle Requirement

The course has TWO hurdles in the final exam that you must meet to pass the course:

Exam Environment

Language Restriction

Fit to Sit

By sitting or submitting an assessment on the scheduled assessment date, a student is declaring that they are fit to do so and cannot later apply for Special Consideration.

If, during an exam you feels unwell to the point that you cannot continue with the exam, you should raise you hand and inform an invigilator, who will provide advice as to the best course of action.

Technical Issues

If you experience a technical issue, you should raise your hand and wait for an invigilator to assist.

Setup

The starter files for this exam will be automatically placed in your home directory. Programs (including your terminal and text editor) are available via the desktop menu (accessible by right-clicking the desktop).
A copy of the course website has been made available. You can access this via the desktop menu also (accessible by right-clicking the desktop).

To test your code (for example, for question 1), run the command:

1511 autotest-prac prac_q1

To submit your code (for example, for question 1), run the command:

submit prac_q1 prac_q1.c

Questions

Question 1
(●◌◌◌)
:

Passing this question, or question 3, is sufficient to pass the linked lists hurdle.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q1

Note prac_q1.c uses the following familiar data type:

struct node {
    struct node *next;
    int          data;
};
sum_divisible is given two arguments, head1 and head2, which are pointers to the first node of linked lists.

sum_divisible should return the sum of the elements in the first list that are divisible by their corresponding element in the second list. In other words, if the ith element of list1 is divisible by the ith element of list2, then you should add the ith element of list1 to the sum.

If one list is longer than the other, the extra elements should be ignored.

You can assume all values in the lists will be greater than 0.

For example, if the two lists contain these values:

list1: 3, 1, 4, 11, 6, 9

list2: 3, 7, 2

sum_divisible should return 7, because

  • The first element in list1 is 3 and is divisible by the first element in list2 which is 3, so we add 3 to the sum.
  • The second element in list1 is 1 which is NOT divisible by the second element in list2 which is 7, so we don't add 1 to the sum.
  • The third element in list1 is 4 which is divisible by the third element in list2 which is 2, so we add 4 to the sum.
  • There are no more elements in list2 so nothing else gets added to the sum.

For example, if the two lists contain these values:

list1: 2, 4, 6

list2: 1, 2, 3

sum_divisible should return 12, because 2 is divisible by 1, 4 is divisible by 2, 6 is divisible by 3, and 2 + 4 + 6 = 12.

Testing

list_sum_disible.c also contains a main function which allows you to test your sum_divisible function.

This main function:

  • uses a command line argument of "-" to separate the values for two linked lists.
  • converts the command-line arguments before the "-" to a linked list
  • assigns a pointer to the first node in the linked list to head1
  • converts the command-line arguments after the "-" to a linked list
  • assigns a pointer to the first node in the linked list to head2
  • calls sum_divisible(head1, head2)
  • prints the result.

Do not change this main function. If you want to change it, you have misread the question.

Your sum_divisible function will be called directly in marking. The main function is only to let you test your sum_divisible function

dcc prac_q1.c -o sum_divisible
./prac_q1 2 4 6 - 1 2 3
12
./prac_q1 3 1 2 - 2 7 9
0
./prac_q1 16 7 8 12 - 13 19 21 12
12
./prac_q1 2 4 6 - 3 2 3
10
./prac_q1 - 1 2 3 4
0
./prac_q1 4 3 2 1 -
0
./prac_q1 -
0

Assumptions/Restrictions/Clarifications.

  • The lists may be different lengths.
  • The data fields of the lists may only contain integers > 0.
  • sum_divisible should return only a single integer.
  • sum_divisible should not change the linked lists it is given.
  • sum_divisible should not change the next or data fields of list nodes.
  • sum_divisible should not use arrays.
  • sum_divisible should not call malloc.
  • sum_divisible should not call scanf (or getchar or fgets).
  • sum_divisible should not print anything. It should not call printf.
  • Do not change the definition of struct node.
  • Do not change the supplied main function. It will not be tested or marked.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q1

Question 2
(●◌◌◌)
:

Passing this question, or question 4, is sufficient to pass the arrays hurdle.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q2

min_lowercase will be passed in a character array with exactly size columns. Add code so that the min_lowercase function returns the lowercase letter with the lowest ASCII value.

Examples

If the array contains these elements:

{'c', 'A', 'e', 'P', '!'}

Your function should return the character 'c' because it is lowercase and has the lowest ASCII value compared to all other characters in the array.

For example if the array contains these elements:

{'O', '@', 'g'}

Your function should return the character 'g' because it is lowercase and has the lowest ASCII value compared to all other characters in the array.

Testing

prac_q2.c also contains a simple main function which allows you to test your min_lowercase function.

Your min_lowercase function will be called directly in marking. The main function is only to let you test your min_lowercase function.

Assumptions/Restrictions/Clarifications.

  • You can assume that the array has at least 1 lowercase letter.
  • You can assume that the array will have at most 100 characters.
  • min_lowercase should not modify the array it is provided.
  • min_lowercase should not call scanf (or getchar or fgets).
  • min_lowercase should not print anything, i.e. It should not call printf.
  • The provided starter code contains a main function. You can change it for your own testing, but it will not be autotested or marked.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q2

Question 3
(●●◌◌)
:

Passing this question, or question 1, is sufficient to pass the linked lists hurdle.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q3

The function insert_alphabet_after is given two arguments, ch and head where head is a pointer to the first node in a linked list.

insert_alphabet_after should find every node in the given linked list which contains the letter directly before ch in the alphabet. It should create new node(s) (using malloc) containing ch and insert it after every node found.

insert_alphabet_after should return a pointer to the head of the list.

In the case that head is empty, you should return a pointer to the new node with the given ch.

For example if ch is c and the linked list contains these 3 elements:

b d e

The character before ch in the alphabet in the list is b, and so the c is inserted after the b, resulting in the list now having these elements:

b c d e

If the ch is e and the linked list contains these 4 elements:

d d d d

The e occurs right after d in the alphabet, and so the e is inserted once after every d in the list, resulting in the list now having these elements:

d e d e d e d e

Testing

prac_q3.c also contains a main function which allows you to test your insert_alphabet_after function.

This main function:

  • converts the command-line arguments to a linked list
  • assigns a pointer to the first node in the linked list to head
  • reads a character from standard input and assigns it to value
  • calls insert_alphabet_after(value, head)
  • prints the result.

Do not change this main function. If you want to change it, you have misread the question.

Your insert_alphabet_after function will be called directly in marking. The main function is only to let you test your insert_alphabet_after function.

dcc prac_q3.c -o prac_q3
./prac_q3 a
b
[a, b]
./prac_q3 d c b a
e
[d, e, c, b, a]
./prac_q3
a
[a]
./prac_q3 h e l l o
a
[h, e, l, l, o]
./prac_q3
h
[h]
./prac_q3 a a b b
b
[a, b, a, b, b, b]

Assumptions/Restrictions/Clarifications.

  • insert_alphabet_after should not use arrays.
  • insert_alphabet_after should not call scanf (or getchar or fgets).
  • insert_alphabet_after should not print anything. It should not call printf.
  • If there are multiple of alphabet characters that come directly before the given ch in the linked list, insert_alphabet_after should insert after every one of those nodes in the list.
  • If the given ch is a, it should only be added if we are adding to an empty list as no alphabet characters come before a.
  • You can assumed all characters in this question will be lowercase alphabet characters (a - z).
  • You cannot assume the given list will be ordered alphabetically.
  • Do not change the supplied main function. It will not be tested or marked.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q3

Question 4
(●●◌◌)
:

Passing this question, or question 2, is sufficient to pass the arrays hurdle.
(12 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q4

vowels_exactly_balanced will be passed an array of strings, with exactly size strings. Each row contains a string terminated by the null terminator ('\0') character. Write the vowels_exactly_balanced function which returns 1 if each string contains exactly the same number of vowels, or 0 if they do not.

Examples

If the array contains these elements:

{'a', 'a', 'a', 'a', '\0'},
{'c', 'o', 'm', 'p', '\0'},
{'o', 'o', 'o', 'h', '\0'},
{'y', 'a', 'y', 'a', '\0'},

Your function should return false (0), since each string does not have the same number of vowels.

For example if the array contains these elements:

{'a', 'b', 'c', '\0'},
{'!', 'e', '\0'},
{'a', 'c', '\0'},

Your function should return true (1), since each string contains 1 vowel.

For example if the array contains these elements:

{'f', 'g', 'h', '\0'},
{'j', '\0'},
{'z', 'x', 'c', 'v', 'b', 'n', 'm', '\0'},

Your function should return true (1), since each string contains 0 vowels.

Testing

prac_q4.c also contains a simple main function which allows you to test your vowels_exactly_balanced function.

Your vowels_exactly_balanced function will be called directly in marking. The main function is only to let you test your vowels_exactly_balanced function.

Assumptions/Restrictions/Clarifications.

  • Uppercase and lowercase vowels all count as vowels. The vowels are 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'.
  • vowels_exactly_balanced can assume there will be at least one string
  • If there is one string, it will always be balanced, so return 1
  • You may assume that the array will only be comprised of any ASCII characters.
  • Your function should return a single integer; 0 for false, and 1 for true.
  • Each string in vowels_exactly_balanced will always have a null terminator character at the final position
  • Each string in vowels_exactly_balanced contains at most 100 characters
  • vowels_exactly_balanced should not print anything. It should not call printf.
  • Your starter code contains a main function. You can change it for your own testing, but it will not be marked.
  • You must not change the given array.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q4

Question 5
(●◌◌◌)
:

(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q5

prac_q5.c is meant to do the following:

  • Scan in an integer representing a month in the year.
  • Print a message indicating the season in Australia for the entered month.
    • From December through to February (12 to 2, inclusive), it is summer in Australia.
    • From March to May (3 to 5, inclusive), it is autumn in Australia.
    • From June to August (6 to 8, inclusive), it is winter in Australia.
    • From September to November (9 to 11, inclusive), it is spring in Australia.
  • If an invalid integer is entered (i.e. when month is less than 1 or greater than 12), an error message is printed.
However, it has some issues that you need to fix.

Once fixed, your program should match the following example exactly:

dcc prac_q5.c -o prac_q5
./prac_q5
Enter the month number (1-12): 0
Invalid month entered.
./prac_q5
Enter the month number (1-12): 12
It's summer in Australia.
./prac_q5
Enter the month number (1-12): 5
It's autumn in Australia.

There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, adding lines, or removing lines. Submit your working version of the code.

Assumptions/Restrictions/Clarifications.

  • You can assume that you will be given an integer for the month.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q5

Question 6
(●◌◌◌)
:

(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q6

compare_tens is given two arguments, head1 and head2, which are pointers to the first node of linked lists.

compare_tens is meant to return -1 if the amount of two digit positive numbers in the first list is less than the number of two digit positive numbers in the second list.

compare_tens is meant to return 0 if the amount of two digit positive numbers is the same in both lists.

compare_tens is meant to return 1 if the amount of two digit positive numbers in the first list is more than the number of two digit positive numbers in the second list.

And for example, if the two lists contain these values:

  • list1: 13, 1, 4
  • list2: 2, 71, 1, 18, 3
compare_tens is meant to return -1, because there is 1 two digit positive number in the first list and 2 in the second list, which means there are less two digit positive numbers in the first list than there are in the second.

For example, if the two lists contain these values:

  • list1: 30, 11
  • list2: 19, 71

compare_tens is meant to return 0, because the first list has the same number of two digit positive numbers as the second list.

However, it has some issues that you need to fix.

Once fixed, your program should match the following example exactly:

Testing

prac_q6.c also contains a main function which allows you to test your compare_tens function.

This main function:

  • uses a command line argument of "-" to separate the values for two linked lists.
  • converts the command-line arguments before the "-" to a linked list
  • assigns a pointer to the first node in the linked list to head1
  • converts the command-line arguments after the "-" to a linked list
  • assigns a pointer to the first node in the linked list to head2
  • calls compare_tens(head1, head2)
  • prints the result.
Do not change this main function. This main function does not contain any bugs.

Yourcompare_tens function will be called directly in marking. The main function is only to let you test your compare_tens function.

dcc prac_q6.c -o prac_q6
./prac_q6 3 1 4 - 2 7 1 8 3
0
./prac_q6 10 16 21 12 - 16 7 8 12
1
./prac_q6 2 4 6 - 42
-1
./prac_q6 -
0

There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, adding lines, or removing lines. Submit your working version of the code.

You can change any code except for the functions that specifically state that they cannot be changed. You can assume the functions you should not change are correct.

Assumptions/Restrictions/Clarifications.

  • You may assume you will also be tested with positive integer inputs
  • Do not change the definition of struct node.
  • compare_tens should return only a single integer and this integer must one of three values: -1, 1 or 0.
  • compare_tens should not change the linked lists it is given.
  • compare_tens should not change the next or data fields of list nodes.
  • compare_tens should not use arrays.
  • compare_tens should not call malloc.
  • compare_tens should not call scanf (or getchar or fgets).
  • compare_tens should not print anything. It should not call printf.
  • Do not change the supplied main function. It will not be tested or marked.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q6

Question 7
(●◌◌◌)
:

(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q7

You have been provided with a file called prac_q7.c.

The code in prac_q7.c is meant to do the following until the user enters Ctrl-D:

  • take an integer as input from the user,
  • pass it to a function to compute the factorial of the number,
  • store the resulting value in the factorial pointer variable, and
  • print the factorial result in the main function.
For example, if the number read in from the user is 5, then the program should output 120 and wait for the next input from the user unless they enter Ctrl-D which will end the program.
dcc prac_q7.c -o prac_q7
./prac_q7
Enter a number: 2
The factorial of 2 is 2 
Enter a number: 5
The factorial of 5 is 120
Enter a number: 7
The factorial of 7 is 5040
Enter a number: 

There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, adding lines, or removing lines. Submit your working version of the code.

Assumptions/Restrictions/Clarifications

  • You may assume the user will always input a positive integer.
  • You may assume that you will never be given an input greater than 10
  • Your compute_factorial function should not print anything.
You can re-fetch the starter code for this question here
You can autotest this code with 1511 autotest-prac prac_q7

Question 8
(●◌◌◌)
:

(5 marks)
You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q8

prac_q8.c is meant to do the following:

This program should create and scan in the elements of a 3x3 2d array, then multiply all the odd numbers in the 2d array by 100.

However, it has some issues that you need to fix.

Once fixed, your program should match the following example exactly:

Examples

dcc prac_q8.c -o prac_q8
./prac_q8
Enter your numbers:
1 2 3
4 5 6
7 8 9
Converted:
100 2 300
4 500 6 
700 8 900
./prac_q8
Enter your numbers:
1 2 3
1 2 3
1 2 3
Converted:
100 2 300
100 2 300
100 2 300
./prac_q8
Enter your numbers:
1 1 1
2 2 2
3 3 3
Converted:
100 100 100
2 2 2
300 300 300

There are currently a number of issues in the code that you must fix for the code to work correctly, and produce the desired output. This may include changing lines, moving lines, or removing lines. Submit your working version of the code.

Assumptions/Restrictions/Clarifications.

  • Your code should produce no errors or warnings when compiling.
  • You can assume the input for this function will be in the form of 9 `int`s, so there is no need for error checking.
  • You can re-fetch the starter code for this question here
    You can autotest this code with 1511 autotest-prac prac_q8

    Question 9
    (●●●◌)
    :

    (11 marks)
    You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q9

    In this question, you will implement the function rotation_shift_amount.

    int rotation_shift_amount(char *str1, char *str2) checks if str2 is a rotation of str1 and returns the amount str2 is rotated relative to str1. If str2 is not a rotation of str1, the function should return -1.

    Rotation in this context means shifting the characters of str1 to the left. For example, if str1 is "hello":

    • Rotation by 0: "hello"
    • Rotation by 1: "elloh"
    • Rotation by 2: "llohe"
    • Rotation by 3: "lohel"
    • Rotation by 4: "ohell"

    For example, if two strings "hello" and "llohe" are given, then the function should return 2 as "llohe" is a rotation of "hello" by 2 characters.

    Examples

    result = rotation_shift_amount("hello", "llohe")
    // result = 2
    
    result = rotation_shift_amount("hello", "olelh")
    // result = -1
    
    result = rotation_shift_amount("", "")
    // result = 0
    
    result = rotation_shift_amount("A really long string with many words", "Hey! Another string :D")
    // result = -1
    

    Assumptions/Restrictions/Clarifications

    • You cannot use the string.h library. If you do so, you will receive a 0 in this question.
    • The given string can be of any size, there is no maximum.
    • You can create your own helper functions if you wish.
    • All strings will end with a '\0' character.
    • Either or both of the given strings may be empty (e.g. only contains '\0').
    You can re-fetch the starter code for this question here
    You can autotest this code with 1511 autotest-prac prac_q9

    Question 10
    (●●●◌)
    :

    (11 marks)
    You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q10

    In this question, we will be writing a system to simulate orders to buy and sell items being sent in a market! Each order is of type "BUY" or "SELL" and contains information about the price, quantity, and a link to the next order. The starter code provided scans in a sequence of orders, and creates a linked list of struct orders, which you can traverse to access the orders.

    We have two types of orders: BUY and SELL, `b` and `s` respectively. A BUY order represents the buyer's willingness to pay up to a given price for a certain quantity of goods, and a SELL order represents the seller's desire to sell a certain quantity of goods at a minimum price.

    The objective is to match BUY and SELL orders based on their prices and quantities, or store them for later matching if no immediate match is found, so that a trade can occur!

    The matching process is as follows:

    1. When a new order is placed, the system attempts to match it with an existing order. For a BUY order, it looks for the lowest-priced SELL order with a price less than or equal to the BUY order's price. For a SELL order, it looks for the highest-priced BUY order with a price greater than or equal to the SELL order's price.
      Note that orders should be processed sequentially. An order can only be matched with another order which appeared before it in the list.
    2. If a matching order is found, then the system will execute the match! It matches as many items as possible, which is the minimum of the quantities in the two orders (e.g, if the orders are "BUY 3 items at $5", and "SELL 6 items at $4", then the match would occur for 3 items). The matched items should then be removed from the orders. If the quantity in one order exceeds the quantity in the other, the system looks for more matches before storing the remaining quantity for later matching.
    3. If the quantities do not match entirely, the remaining items in the unmatched order are stored for further matching attempts with other orders.
    4. The matching then process continues until all possible matches are made!
    Once the matching process is complete, your program should print the remaining unmatched orders in decreasing price order, along with their type and quantity. For example:
    SELL 7 items for $6
    BUY 6 items for $4
    

    Assumptions/Restrictions/Clarifications

    • Orders should be processed sequentially. An order cannot match with another order which appears after it in the list, until that later order is processed.
    • You can assume that the price and quantity given will always be positive, and that the order type will always be b or s.
    • You will need to ensure there are no memory leaks in your code to successfully complete this question.

    Examples

    The following diagrams are worked examples, showing the operation of the system step-by-step.

    Note: The format in which orders are entered is [order_type] [quantity] [price].

    dcc prac_q10.c -o prac_q10
    ./prac_q10
    b 5 8
    b 7 9
    s 7 10
    s 5 9
    
    SELL 7 items for $10
    BUY 2 items for $9
    BUY 5 items for $8
    ./prac_q10
    s 12 10
    s 7 9
    b 7 8
    b 11 11
    s 6 5
    b 8 10
    
    BUY 1 items for $8
    ./prac_q10
    b 10 3
    b 6 4
    s 7 6
    
    SELL 7 items for $6
    BUY 6 items for $4
    BUY 10 items for $3
    ./prac_q10
    b 10 5
    s 10 5
    
    ./prac_q10
    b 15 7
    b 10 6
    s 7 4
    s 12 5
    
    BUY 6 items for $6
    ./prac_q10
    s 10 12
    s 9 7
    b 8 7
    b 9 11
    s 6 2
    b 5 10
    
    SELL 10 items for $12
    BUY 2 items for $11
    BUY 5 items for $10
    
    You can re-fetch the starter code for this question here
    You can autotest this code with 1511 autotest-prac prac_q10

    Question 11
    (●●●●)
    :

    (10 marks)
    You can fetch the starter code for this question here or by running 1511 fetch-prac prac_q11

    In this question, we will write a program to help us validate the format of our dcc commands, and print information about them!

    The input for this question will be a series of commands entered via standard input, representing either:

    • a dcc command that you might use to compile a single or multi-file project. When you encounter one of these commands, you will need to validate the command against a set of rules, described below. In addition to the standard rules you might be used to, we've added some extra rules of our own, so make sure to read the rule list carefully!

      If the command is valid, then it will produce an executable. This is explained in more detail later.

    • a command to "run an executable". This command will be in the form ./[executable_name]. If a previously run dcc command successfully created the given executable, then "running the executable" should output information about the files used to compile that executable. For example, if the executable my_program was compiled with the command dcc my_program.c other_file.c -o my_program, then running my_program should produce the following output:

      Executable 'my_program' was compiled using the following files:
       - my_program.c
       - other_file.c
            

      If the executable name does not match any produced by previous dcc commands, then the message "Executable [executable_name] not recognised!" should be printed.

    The rules for validating a given dcc command are as follows:

    • The first argument in the command must be "dcc"
    • There must be exactly one "-o" argument, which must be followed by a valid "executable name"
    • For an "executable name" to be valid, it must:
      • Not end with ".c",
      • exactly match the name of a provided ".c" file - e.g, an executable "foo" matches with "foo.c", but does not match "bar.c", or "foobar.c"
    • All other arguments should be a file name ending in ".c"

    If any of the above rules are not satisfied, the program should print "Invalid command!". If all the rules are met, then the program should print "Executable [executable_name] compiled!", and store information about the executable.

    If a dcc command creates an executable with the same name as an existing executable, then the original executable should be overwritten and, replaced with the new one.

    Examples

    dcc prac_q11.c -o prac_q11
    ./prac_q11
    # dcc main.c -o main
    Executable main compiled!
    # 
    ./prac_q11
    # dcc main.c test.c -o main
    Executable main compiled!
    # dcc main.c main
    Invalid command!
    # dcc main.c -o test
    Invalid command!
    # dcc main.c
    Invalid command!
    # dcc main.c -o main.c
    Invalid command!
    # dcc main.c.c -o main.c
    Invalid command!
    # dcc main.py -o main
    Invalid command!
    # 
    ./prac_q11
    # dcc main.c test.c -o test
    Executable test compiled!
    # ./test
    Executable 'test' was compiled with the following files:
     - main.c
     - test.c
    # dcc other_file.c test.c -o test
    Executable test compiled!
    # ./test
    Executable 'test' was compiled with the following files:
     - other_file.c
     - test.c
    # dcc broken_command.c -o test
    Invalid command!
    # ./test
    Executable 'test' was compiled with the following files:
     - other_file.c
     - test.c
    # 
    ./prac_q11
    # dcc main.c -o main
    Executable main compiled!
    # dcc test.c -o test
    Executable test compiled!
    # dcc file.c -o file
    Executable file compiled!
    # ./main
    Executable 'main' was compiled with the following files:
     - main.c
    # ./test
    Executable 'test' was compiled with the following files:
     - test.c
    # ./file
    Executable 'file' was compiled with the following files:
     - file.c
    # 
    

    Assumptions/Restrictions/Clarifications

    • You should not add to the list of rules given above - that is, do not add any of your own rules, or attempt to replicate the behaviour of dcc.
    • .c file names must not be empty - that is, ".c" is not a valid file name.
    • You can assume that input will either begin with dcc (meaning that it will be a dcc command), or the first argument will begin with ./ (meaning that it will be a command to run an executable).
    • Files should be listed in the order in which they appeared in the compilation command.
    • Your program must free all memory allocated with malloc before terminating.
    You can re-fetch the starter code for this question here
    You can autotest this code with 1511 autotest-prac prac_q11