1. constructor function to add two numbers together
06main.c
#include <stdio.h> #include "06add.h" int main() { int val = add(3, 5); printf("val是%d\n", val); return 0; }
06add.c
int add(int val, int val1) { return val + val1; }
06add.h
#ifndef __06ADD_H__ #define __06ADD_H__ int add(int, int); #endif //__06ADD_H__
Compile way gcc 06main.c 06add.c
2. Compile function allows the user to get input from the keyboard in order not to be the main function calls, do not .h file statement
07main.c
/ * Call to get the main function * / #include <stdio.h> #include " 07get.h " int main () { GET (); the printf ( " number is obtained by D% \ n- " , Result); return 0 ; }
07get.c
/ * Get an integer * / #include <stdio.h> #include " 07get.h " static int Result = 0 ; // add the other files can not use static int SC () { int Val = 0 ; the printf ( " Please enter a number: " ); Scanf ( " % D " , & Val); return Val; } void GET () { Result = SC (); }
07get.h
__07GET_H__ #ifndef #define __07GET_H__ extern int Result; // function to obtain a value outside the void GET ( void ); #endif // __07GET_H__