How to invoke function from external .c file in C?

前端 未结 8 1830
清酒与你
清酒与你 2020-12-23 19:31

My files are

// main.c  

#include \"add.c\"

int main(void) {
    int result = add(5,6);
    printf(\"%d\\n\", result);
}  

and

         


        
8条回答
  •  别那么骄傲
    2020-12-23 20:15

    You must declare int add(int a, int b); (note to the semicolon) in a header file and include the file into both files. Including it into Main.c will tell compiler how the function should be called. Including into the second file will allow you to check that declaration is valid (compiler would complain if declaration and implementation were not matched).

    Then you must compile both *.c files into one project. Details are compiler-dependent.

提交回复
热议问题