It is not easy to answer not knowing what exactly you don't understand, but I'll try anyway, using my very limited C experience.
What is a preprocessor?
A preprocessor is a program that does some kind of processing on the code file before it is compiled. You can, for example, define a symbolic constant with a preprocessor directive:
#define PI 3.14159
Then you can use this value with a meaningful name across your code:
area = r * r * PI;
...
circumference = 2 * r * PI;
What the preprocessor does here is replace all occurrences of PI with the numeric value you specified:
area = r * r * 3.14159;
...
circumference = 2 * r * 3.14159;
You can also include code depending on whether or not a constant has already been defined somewhere else in your code (this is typically used in projects with multiple files):
#define WINDOWS
...
#ifdef WINDOWS
/* do Windows-specific stuff here */
#endif
The lines between #ifdef
and #endif
will only be included if the constant WINDOWS
is defined before.
I hope that by now you have some idea about what your program should do.
Tips on implementing the "minimum features"
Here I'm going to give you some ideas on how to write the minimum features your professor requires. These are just off the top of my head, so please think about them first.
Stripping off of comments
While reading the input, look for "/*
". When you encounter it, stop writing to the output, then when you find "*/
", you can start writing again. Use a boolean flag to indicate whether you are inside a comment (AFAIK, there is no bool type in C, so use an int with 0 or 1, or, more ideally, two symbolic constants like INSIDE_COMMENT
and OUTSIDE_COMMENT
).
#define for constants (not macros)
If you encounter any line beginning with #, obviously you should not write it out. If you find a #define
directive, store the symbolic name and the value somewhere (both strings), and from then on, look for the name in the input, and write out the value instead each time it is found. You can set a maximum length for the constant name, this is I think 6 chars in C, and always check 6 characters from the input. If the 6 characters begin with a known constant name, write out the value instead.
#ifdef and #endif
Create a boolean flag to indicate whether you are inside an #ifdef
, much like with comments. When finding #ifdef
, check if you are already storing the constant name, and write to the output depending on that.
I hope this helps.
EDIT: also read the comment by gs!