Define multi file program, C/C++ Programming

Assignment Help:

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.


Related Discussions:- Define multi file program

Program, program to check whether a given point lies inside a rectangle or ...

program to check whether a given point lies inside a rectangle or not

Explain abstract classes, Abstract Classes Abstract classes are the cla...

Abstract Classes Abstract classes are the classes, which are written just to act as base classes. Consider the following classes.                 class base

Illustration of plot function, Illustration of Plot function: To be mo...

Illustration of Plot function: To be more common, the script could prompt the user for the time and temperature, instead of just assigning the values. Then, the axis function

Program to calls to echo the typed characters, Write a main program that us...

Write a main program that uses these system calls to echo the typed characters. The pseudo code will look something like: void traphandler ()  {    if (R0 == 0) { // read sys

Program is to define a class as library, Program is to define a class as li...

Program is to define a class as library: Program is to define a class as library and perform all the function of library management by using classes and object class librar

Matlab to c conversion, i am a engineering student and am working on a proj...

i am a engineering student and am working on a project in audio processing and so i have designed a FIR filter in Matlab . how can i get my Matlab program converted to C program?

What is object variable, The definition of an object(variable ): We can...

The definition of an object(variable ): We can explain a variable(set memory to the variable) in the following ways. e.g. double salary; int month; When more than o

Can i overload operator == so it allow me compare two char[], Q: Can I over...

Q: Can I overload operator == so it allow me compare two char[] by a string comparison? A: No: at least one operand of particular overloaded operator should be of some user-defi

Algorithm, Write an algorithm to print all even numbers in descending order...

Write an algorithm to print all even numbers in descending order and draw the flowchart.

There are ''''n'''' ants on a ''''n+1'''' leng n, There are ''''n'''' ants ...

There are ''''n'''' ants on a ''''n+1'''' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are mov

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd