"chellappa" <N.*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi EveryBody!
i need a information about creatting structure at runtime....
like example
....
int main()
{
char *a,*b;
printf("Enter the structure");
scanf("%s",a);
printf ("Enter The Datatype");
scanf("%s",b);
create(a,b);
}
void create(char *F,Char *G);
{
struct F
{
G a;
}
}
i hope u will understand this program... this example ,but i need
inforamtion any possibleties to create struct and its field in runtime
, that user will define..
if posssible give me reply
1. To create something in runtime you first need allocate memory to it
provided you know the size of that something.
2. It is impossible to define (note, not create) something in a C program
after it has been compiled. C programs are compiled, not interpreted. I they
had been interpreted, it would probably have been possible to define
something on the go. Hence, interpretation is to be done by you...
3. Think well whether this is indeed what you need in your program. Can't
you define all what need in the program and then create one of those known
things?
4. What you can do though is...
4a. generate C source code for another program in your original program,
compile and run it -- not sure it's suitable but it's possible
4b. in your program ask the user exactly what he needs inside the structure
(what types), calculate offsets and sizes of the members so that it would be
possible to allocate enough memory for the structure and fill in all its
members at proper addresses
HTH
Alex
P.S. Consider (3) or (4b)