On October 14, 2008 16:25, in comp.lang.c, Adam Chapman
(ad**********@s tudent.manchest er.ac.uk) wrote:
Thanks guys.
Looking at the C example at http://en.wikipedia.org/wiki/Opaque_pointer
, Could you show me how to use the create_Cat function from my main
script? I'ts difficult to tell what inputs I need, most probably
because Im dumb. I think it would be something like this:
#include "cat.h"
main(void){
int smile;
smile = 1;
.... create_Cat(int smile);
}
But am not sure what to put in the place of the .... .
OK. You /really/ need help learning C, don't you. Are you certain that your
name isn't "Bill Cunningham"?
1) You will need to compile the second set of logic shown on that webpage,
either as part of the source code file (officially, the "translatio n unit")
that your main() function is in, or as a separate source code file. If you
choose to make it a separate source code file, you will have to instruct
your linker to use the compiled functions when it links your main()
function.
2) The "cat.h" example file given on the webpage is incomplete. It provides
typedef struct cat_t *cat_handle;
which makes the typename cat_handle to be an alias to the type
"pointer to struct cat_t"
but it /does not/ define the
struct cat_t
at all. However, you can find the structure definition for cat_t in the
second example code. My recommendation would be to remove it from the
second example, and move it to the cat.h header.
3) You actually had a good start in the lines above. Assuming that you move
the cat_t structure definition to cat.h, you will need something like...
#include "cat.h"
int main(void)
{
cat_handle MyCat;
MyCat = createCat(1);
/* what ever other logic you want to use goes here */
return 0;
}
HTH
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------