I have 2 structure name struct1, struct2. also i have one manipulation function named "myFun"
void myFun(/one pointer argument/)
i have a set flag , if set flag is 1 i need to pass struct1 pointer as myFun argument if set flag is 0 i need to pass myFun argument as struct2 pointer .
is it possible, how can i do this
sample (non working) code i tried is shown below.
#include <stdio.h>
#include <string.h>
typedef struct struct1{
int a;
int b;
}struct1;
typedef struct struct2{
int a;
}struct2;
void myFun(void *arg, int select)
{
if(select)
{
arg->a = 10;
arg->b = 20;
}
else
{
arg->a = 100;
}
}
int main() {
// Write C code here
int select = 0;
struct1 t1;
struct2 t2;
printf(enter the select option 0 or 1);
scanf("%d",select);
if(select)
{
myFun((void *)&t1,select);
}
else
{
myFun((void *)&t2,select);
}
return 0;
}