Monday, November 14, 2022

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

Issue

My files are

// main.c  

#include <ClasseAusiliaria.c>

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

and

// add.c  

int add(int a, int b) {
    return a + b;
}

Solution

Use double quotes #include "ClasseAusiliaria.c" [Don't use angle brackets (< >) ]

And I prefer to save the file with .h extension In the same directory/folder.

TLDR: Replace #include <ClasseAusiliaria.c> with #include "ClasseAusiliaria.c"



Answered By - Gaurav Jain
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.