I have large main file contains about 7,000 lines of C code. If I want to make this code modular and separate the code from this file. what is the main criteria for separating the functions out of the file and functions that should stay in the file.
Reading from file (fscanf or fgets) Writing to a file (fprintf or fputs)
The best way to organize your engagement program is with folders. Make a folder for each stream and then put the emails or programs into that folder. Include an archive folder in each stream when content gets stale and you want to remove it.
To write a C code file in Notepad, type your C code into a blank page in the text editor, and then save the file with a ". c" file extension if the file consists of a C code page, or the ". h" file extension if the file consists of header code.
I like to use a top-down decomposition of the code. For example:
main()
{
Initialize();
Introduce();
while (some_condition)
{
DoSomething();
DoSomethingElse();
}
SayGoodbye();
Shutdown();
}
The main()
should be short and to the point and give you a quick overview of what the program does from a high-level. Each of these functions can be broken down in a similar way. This should continue until the lowest level functions have a single, focused purpose (logical modularity). These functions can be put into additional .c/.h files to have physical modularity.
Good luck!
Break up by functionality/responsibility.
For example, place all string handling in one module/file, place file handling in another.
It is a simple measure: the fewer declarations you have in the .h file, the more modular it is. Grouping by functionality is important. Having extern declarations is very bad, give those an extra 'penalty'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With