How do I use the following function? /* sets the variable referenced by r to zero and returns the previous value of r */ int testfunc(int *r); Code (markup): I'm trying the following but no luck? #include <stdio.h> #include "testfunc.h" int main() { int testValue=1; int testResult; testfunc(testValue); printf("Test value now equals %d\n",testValue); printf("Returned value equals %d\n",testResult); return 0; } Code (markup):
Hi, try this: int main(){ int testResult,testValue=1; testResult = testfunc(&testValue); printf("Test value now equals %d\nReturned value equals %d\n",testValue,testResult); return 0; } PHP:
I'm receiving the following error when compiling: gcc testlscore.c -o testscore /tmp/ccQRp93p.o: In function `main': /tmp/ccQRp93p.o(.text+0x26): undefined reference to `testfunc' collect2: ld returned 1 exit status Code (markup):
It seems you forgot to include the file with testfunc(). testfunc.h holds only function prototype definition (I guess), not the function itself: testfunc.c or testfunc.cpp? Here is my test and it works under Xubuntu: #include <stdio.h> int testfunc(int *r); int main(void){ int testResult,testValue=1; testResult = testfunc(&testValue); printf("Test value now equals %d\nReturned value equals %d\n",testValue,testResult); return 0; } int testfunc(int *r){ int tmp; tmp=*r; *r=0; return tmp; } PHP: