how to add a member variable/attribute to a structure from main in C?
-
1If you are asking this question to solve a problem, then may want to explain your problem. That way you get answers different to: "No!".quinmars– quinmars2009-09-25 08:23:05 +00:00Commented Sep 25, 2009 at 8:23
-
This stackoverflow.com/questions/1218947/convert-a-string-in-c-code is related (but not a duplicate), and you might find some help there.dmckee --- ex-moderator kitten– dmckee --- ex-moderator kitten2009-09-25 21:49:34 +00:00Commented Sep 25, 2009 at 21:49
Add a comment
|
2 Answers
You can't. C is not a dynamic programming language.
You can, however, define an array in your struct; and allocate memory to that array. Perhaps this can solve your current problem?
3 Comments
Chris Lutz
You don't allocate memory to an array, you allocate memory to a pointer. An array is stored directly in the
struct and is a different beast.Jonathan Leffler
@Chris: I see what you're saying, but it isn't all that clear. The answer, perhaps, should say: "You can, however, define a pointer in your structure, and you can dynamically allocate memory for an array and place the pointer to that allocated array in the structure (probably with a counter too)".
phoebus
@Chris while from a technical standpoint that's true, I think the semantics were clear.