Practice Assignment

(stripcom.c)

Information

  1. For this practice assignment you will write a function that strips out all of the comments in a C source file. Here's an example:

    This is the input file: input1.txt:

    /************************************* A simple header comment *************************************/ int main(void) /* help */ { /* a comment before */ /* in front */ int a = 8/4; /* at end */ /* a comment after */ return a; }

    The file after running the program on it: output1.txt

    int main(void) { int a = 8/4; return a; }

    The border shows you that there is one blank line above the line containing main. There is also one blank line above the int a line and 2 blank lines below it.

    This is the prototype for the function:

    void stripcom(const char *filename);
    
    and this is the command line to compile it:
    gcc -O -Werror -Wall -Wextra -ansi -pedantic main.c stripcom.c -o stripcom
    
    Additional tests:

    Here is a simple driver file: (main.c, HTML Text) You must specify the filename on the command line like this:

    stripcom foo.c
    


Notes: