Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing void parametre

Status
Not open for further replies.

BorlandDave

Programmer
Jun 13, 2005
86
GB
I have some code to edit which I don't fully understand. Here it is...

struct TDelrecs_tbl{
int table_no;
int pk1, pk2;
};

void function1(void){
TDelrecs_tbl delrec;

delrec.table_no=1;
delrec.pk1=2;
delrec.pk2=3;

function2(&delrec);
}

void function2(void *dbstruct){
pFile = fopen("C:\\DAVE_function2.txt","a+");
fprintf(pFile,"%i,%i,%i\n",dbstruct.table_no,dbstruct.pk1,dbstruct.pk2);
fclose(pFile);
}

I'm just trying to write out the variables of the struct to a file in the second function. The way the struct is passed between functions can't be changed. Can anyone make this work? Cheers.
 
Just noticed I missed the line: FILE *pFile; at the top of the second function. Just letting you know that isn't the cause of the problem! I've never seen a void parametre used before.
 
Nevermind. I think I've just worked it out! By recieving the parametre as a void, the program just recognises it as a raw pointer to a memory address.

To access the struct data, I must first cast the pointer as a pointer to a TDelrecs_tbl structure by:

*(TDelrecs_tbl *) dbstruct
 
There you go! Is there anything more i can help with? ;-)

Totte
Keep making it perfect and it will end up broken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top