Hi, I have a problem with sturcts. I have something like : Code: struct stack1 { int number; struct stack1 *next; }; I want to create structs as user request. I mean, i`ll get some number from the user input, and create this number of startcts. For example, i got the number 3 from the user. Automaticly create : stack1 s1; stack1 s2; stack1 s3; ( 3 structs ). I dont care the structs names. I hope the explanation was clear, Thanks for helpers. Or.
Arrays are your friend, and malloc. Code: int i=5; // or get this from the user struct stack1 *ptr=(struct stack1 *)malloc(sizeof(struct stack1)*i); // do whatever you want with ptr, e.g. ptr[3].number=5; // which sets the array's *4th* entry number to 5. // and DO NOT EVER FORGET: free(ptr);