This project is a C program that processes a source code file (myprog.c) and expands #define macros, replacing occurrences of defined macros with their corresponding values. The program reads the file, identifies #define directives, and substitutes macro occurrences while maintaining the structure of the original file.
- Reads a C source file (
myprog.c). - Identifies and stores
#definemacro definitions. - Replaces all instances of macros with their defined values.
- Removes
#definedirectives from the final output. - Writes the processed code into a temporary file without macros.
- The program reads
myprog.cand counts characters, lines, and longest line length. - It extracts
#definemacro definitions and stores them in separate buffers. - It creates a temporary file (
temp.txt), replacing occurrences of macros with their values. - It removes all
#definedirectives from the processed file. - The final output is written into
temp2.txtand then restored totemp.txtbefore cleanup.
- GCC Compiler
- C Standard Library (stdio.h, stdlib.h, string.h)
To compile the program, run:
gcc -o macro_expander macro_expander.cRun the program with:
./macro_expanderEnsure myprog.c exists in the same directory before execution.
- Assumes
#definemacros follow a simple format. - Does not handle multi-line macro definitions.
- Limited to
#definereplacement without parameterized macros.
This project is open-source and licensed under the MIT License. Contributions and improvements are welcome!
Akash Sureshbhai Khanpara