-
ahhh, noob question.
I'm using DevC++ and im trying to call a function that is written in another '.c' file that is included in the project
umm heres an example of what im trying to do.
~MAIN.C~
Code:
#include <stdio.h>
#include "func.c"
int main()
{
callprint("hello world!");
getchar();
return 0;
}//end of main
~FUNC.C~
Code:
#include <stdio.h>
void callprint(char text[])
{
printf(text);
}
it keeps comming up with multi definition of callprint(char text[])
-
You never include .c files, you include .h files.
func.h:
Code:
#ifndef __FUNC_H__
#define __FUNC_H__
void callprint(char text[]);
#endif
func.c:
Code:
#include <stdio.h>
void callprint(char text[])
{
printf(text);
}
main.c:
Code:
#include <stdio.h>
#include "func.h"
int main()
{
callprint("hello world!");
getchar();
return 0;
}//end of main
-
> it keeps comming up with multi definition of callprint(char text[])
That's because you #include the source code (that's one copy), and you also compile it as a separate file (that's two).
Do as rags_to_riches says and create a header file.
Oh, and
printf(text);
is extremely dangerous.
If you make the mistake of passing a string with formats (like %d), then the call to printf becomes undefined (no extra parameters you see).
Use fputs() in this instance, or perhaps
printf("%s",text);