Calling a function in a2.c in the source file a1.c
There are two ways of doing this:
1. There is a complete function definition in a2.c, add the function prototype (declaration) to be used in a1.c, for example:
In a2.c: There is a function void A2 () {...};
In a1.c: Add a line to the front of the file: void A2 ();
2. Write the prototype of the fully defined function in a2.c to a A2.h file, and add # include "A2.h" to the a1.c file header.
Both of these methods can be called normally in a1.c, just as in a2.c.
In fact, the function is external by default, as long as it is declared in other files, but note that if it is preceded by static, it can only be used in this file and can no longer be called by other files.
How to write a header file
1. An. h file should have a. c file, which helps to view and modify the program. such as A.h and A.C;:
In the. h file
#ifndef __a_h_
#define __a_h_
void Trans2 (double B);
Double trans1 () ;
#endif
2. Write the corresponding function definition in the. c file
3. Add # include "A.h" at the beginning of the Main.c file
How to call another source file function in C language