Class 1
Max
John
Jessy
Stephany
Class 2
Daniel
Katie
Tom
Class 3
Carlos
Jess
Aaron
I want to store this data in the computer memory but I don't know how to connect John with Class 1, Katie with Class 2, etc. How can I do this? Thanks.
Class 1
Max
John
Jessy
Stephany
Class 2
Daniel
Katie
Tom
Class 3
Carlos
Jess
Aaron
I want to store this data in the computer memory but I don't know how to connect John with Class 1, Katie with Class 2, etc. How can I do this? Thanks.
You can make a structure of a class, and make 3 instances of that structure.
Code:struct class { char *students[100]; int seat; int class_num; };You should be able to figure the rest out.Code:class *class1; class1->students[1] = "God";
Maybe that last line was meant to beCode:char *students[100]; // ... class *class1; class1->students[1] = "God";
Code:strcpy(class1->students, "God");
[edit]
Oh, and by the way . . .
class is an invalid name. It's a keyword.Code:struct class {
[/edit]
Last edited by dwks; 08-20-2005 at 07:48 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
The problem is that I don't know how many classes I'll have and how many students each class will have. It has to be something dinamic
You could use an array of classes.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
> class is an invalid name. It's a keyword
Nope - it's a perfectly valid name in C
> The problem is that I don't know how many classes I'll have
So create a linked list of classes.
Personally, I'd also have a linked list of students in each class.
Do a search, there's plenty of prior discussion on linked lists.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I would go something like this:
This way your class can be as big or as small as you would like it to be.Code:struct student{ char *name; int seat; int class_num; }; struct class{ struct student *students; };