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
#define
macro definitions. - Replaces all instances of macros with their defined values.
- Removes
#define
directives from the final output. - Writes the processed code into a temporary file without macros.
- The program reads
myprog.c
and counts characters, lines, and longest line length. - It extracts
#define
macro definitions and stores them in separate buffers. - It creates a temporary file (
temp.txt
), replacing occurrences of macros with their values. - It removes all
#define
directives from the processed file. - The final output is written into
temp2.txt
and then restored totemp.txt
before cleanup.
- GCC Compiler
- C Standard Library (stdio.h, stdlib.h, string.h)
To compile the program, run:
gcc -o macro_expander macro_expander.c
Run the program with:
./macro_expander
Ensure myprog.c
exists in the same directory before execution.
- Assumes
#define
macros follow a simple format. - Does not handle multi-line macro definitions.
- Limited to
#define
replacement without parameterized macros.
This project is open-source and licensed under the MIT License. Contributions and improvements are welcome!
Akash Sureshbhai Khanpara