Is it possible to return a char Pointer even the calling function is not in the same file…. if I call the function for example:
void gotest(sqlite3 *pt,char *nutzers)
{
char string[1064];
char *text;
text = get_data_byName(pt,"whatever",string);
printf("test %s \n\n\n same file",text);
}
char *get_data_byName(sqlite3 *ptr,char *user,char *resulter)
{
.......
resulter = "TestCall";
return resulter;
}
if gotest(sqlite3 *pt,char *nutzers) and char *get_data_byName(sqlite3 *ptr,char *user,char *resulter) are in different files then gcc gives the following
Assignment makes pointer from integer without a cast
if I have both functions in one file everything works fine.
compiling like:
gcc -o test test.c time.c database.c libircclient-1.6/src/libircclient.o -lsqlite3
You need headers for your files. If GCC doesn’t see a function prototype in the file it’s used in, GCC assumes that the function returns an
int. You need to read up on headers. In the mean time, putting this in the file where you useget_data_byNamewill be enough:You have to remember that although when GCC is linking, it knows that you define
get_data_byName, when it’s compiling, it needs to know what parameters and return values it has. That’s the purpose of a header. Headers contain function prototypes. A function prototype looks like this:If you put the prototypes of all of the functions defined in one
.cfile in one.hfile, and them#includethat header in the files that use the function, you wont get that error anymore. So if you have a file calledget_data_by_name.c, this would beget_data_by_name.h:Then just
#includeit in the file that usesget_data_byName: