Define multi file program, C/C++ Programming

Define Multi File Program?

While writing large programs we must divide programs up into modules. These would be separate source files and the main() function would be in one file main.c say the other files will contain functions. This is especially true of programs that make use of lengthy functions, where each function may take up a separate file. Or, if there are many small related functions within a program, it may be desirable to place a few functions within every of several files. The individual files will be compiled alone and then linked together to form one executable object program. This facilitates the debugging and editing of the program, ever since each file can be maintained at a manageable size.

Where a function is spread over numerous files every file will contain one or more functions. One file will include main while the others will hold functions which are called by others. These other files are able to be treated as a library of functions. Programmers generally start designing a program by dividing the problem into simply managed sections. Each one of these sections might be implemented as one or more functions and all functions from each section will typically live in a single file. Where the file holds the definition of functions which return values there is a further limitation on calling these functions from another file. Except functions in another file are told about the function definitions and they will be unable to compile them correctly. The most excellent solution to this problem is to write a header file for each of the C files. This will contain the same name as the C file, but ending in .h. The header file holds definitions of all the functions used in the C file.

when a function in another file calls a function from our C file it is able to define the function by making a #include of the appropriate .h file.

mainfile.c

sum_func.h

showresult.h

# include

# include

# include

main()

{

            int a=3,b=5;

            sum(a,b);

}

# include

int sum(int x,int y)

{

            int sum;

            sum=x+y;

            show(sum);

}

void show(int value)

{

            printf("sum is = %d",value);

            getch();

}

In the above program two functions are stored in showresult.h and sum_func.h and main() function is saved in mainfile.c. Throughout preprocessing phase# include and # include copy the whole content of the corresponding header files into the mainfile.c.

Posted Date: 6/13/2013 6:15:30 AM | Location : United States







Related Discussions:- Define multi file program, Assignment Help, Ask Question on Define multi file program, Get Answer, Expert's Help, Define multi file program Discussions

Write discussion on Define multi file program
Your posts are moderated
Related Questions
Define One's Complement Operator? The one's complement operator, occasionally called the "bitwise NOT" or "bitwise complement" operator produces the bitwise one's complement of

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

What is constructor or ctor? need help


#questioA Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a str


how to write a program for all the types of beam reactions

Make the following 3 functions work by filling in appropriate C code. This file 1. // Write a function to count the number of particular characters in a string. // Do not use a

Implement (a part of) electronic election Scenario where following political parties are participating in election: PPP, PML and PTI.  Create a class PollingStation where it stor

Define a complex number in c program: class complex                                 {                                   private:                                 in