CS 2213 Advanced Programming Final Exam Practice Problems: Spring 2001

  1. Write a main program which prints the number of command line parameters followed by each parameter, one per line. The name of the program should be included.
  2. Write a version of the string function
    char *strncpy(char *s1, char *s2, int n);
    which copies at most n characters of the string s2 into s1 and returns a pointer to the destination string. It assumes that enough space has been allocated for the destination. Do not use any library functions.
  3. Use int getchar(void), int putchar(int c), and other library routines to write a filter that will number the lines of the input. Do not assume a maximum line length. If the input contained the lines:
    this is a test
    this is only a test
    but this is an important test.
    
    The output would be:
    1. this is a test
    2. this is only a test
    3. but this is an important test.
    
  4. Consider the doubly linked list pictured below that uses the following typedefs:
    typedef struct {        typedef struct nodeentry {       tyepdef struct {
       char *str;              stringval sval;                  nodeentry *front;
       int val;                struct nodeentry *tofront;       nodeentry *rear;
    } stringval;               struct nodeentry *torear;     } list;
                            } nodenetry;
    
    Write the functions described below. Notice that in each case a pointer to the list is passed since some of the functions might have to change the list.