passing different structs to a function in c
Posted
by clear2k
on Stack Overflow
See other posts from Stack Overflow
or by clear2k
Published on 2010-03-22T23:40:37Z
Indexed on
2010/03/22
23:51 UTC
Read the original article
Hit count: 146
I have different structures that need to be filled out the same way. The only difference is that they are filled based on different data.
I was wondering if it's possible to pass different structures to a certain function. What I have in mind is something like:
struct stu1 {
char *a;
int b;
};
struct stu2 {
char *a;
int b;
};
static struct not_sure **some_func(struct not_sure *not_sure_here, original_content_list)
{
// do something and return passed struct
for(i=0; i<size_of_original_content_list; i++){
//fill out passed structure
}
return the_struct;
}
int main(int argc, char *argv[])
{
return_struct1 = some_func(stu1);
return_struct2 = some_func(stu2);
// do something separate with each return struct...
}
Any comments will be appreciate it.
© Stack Overflow or respective owner