COMP1721 - Higher Computing 1B

Computing 1B - Week 08 Tutorial Questions

  1. Write a C program which asks the user to enter an integer n, then reads n integers from standard input and then prints them in reverse order.

    Make no assumptions about how large n may be.

  2. Write a C program which reads integers from standard input until a negative integer is read, it should then print them in reverse order.

    Make no assumptions about how many integers will be entered.

  3. Write a C function that splits a comma-separated string into substrings. The function's prototype should be:
    char **split(char *s)
    
    The original string should not be changed. The function should return an array of pointers to the substrings. The last element in the array should be NULL.

    The memory for both the array and the substrings should be allocated with malloc.

    For example: given the string "ab,cdef,ghi", the function should return a four element array the first three elements should be pointers to the strings "ab", "cdef", "ghi". The last element should be null.


Andrew Taylor (andrewt@cse.unsw.edu.au)
Higher Computing 1B, Computer Science & Engineering, UNSW