I am currently learning about header files in C, and i keep getting the "undefined reference" error message.
My source code:
main.c:
#include <stdio.h>
#include "answer.h"
void main()
{
printf("The answer is %f\n", WhatIsTheAnswer().answer);
}
answer.c:
#include "answer.h"
struct Answer WhatIsTheAnswer()
{
struct Answer TheAnswer;
TheAnswer.answer = 42.0;
return TheAnswer;
}
answer.h:
#ifndef ANSWER_H
#define ANSWER_H
struct Answer {
float answer;
};
struct Answer WhatIsTheAnswer();
#endif
This code works in VS, but not in VS code.
I know one possible solution is using #include "answer.c"
,
but its problematic and i hope to find a better solution.