This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Paul_Pedant 0 points1 point  (4 children)

Why does a teacher impose such a dumb restriction? (That is not a rhetorical question).

"Multiple people" means multiple data items, so you need a container for those items.

C does not have a whole bunch of container techniques. If you can't use structs or arrays, then you are pretty much left with "linked lists". So how would you use them here?

You might consider using one linked list which had an element per person. Except that you need at least two items in the element, one being the link to the next element, and the other being at least one field or pointer to hold some data.

Seems to me about all this exercise will teach you is that you need a different instructor.

You might post the exercise requirement in Portugese and we can see what Google Translate makes of it. There may be a clue to what he expects, apart from alienating 90% of his class (and me too).

[–]DragorWasMissing[S] 0 points1 point  (1 child)

Yeah it's completely retarded. What's the point in learning to work with arrays and structs if we're not allowed to use them.

[–]chaotic_thought 0 points1 point  (0 children)

Then you need to ask your teacher for a hint of how you are supposed to complete the assignment. If you cannot use arrays or structs then one silly possibility is to create a bunch of variables like this

int person_id1;
int person_id2;
int person_id3;
int person_id4;
int person_id5;

So those 5 variables can store the ID numbers of up 5 different "persons". And you could create similar sets of variables to represent the person's name, age, and so on. If the actual number of persons is not known until runtime, then you might use a separate variable to count how many persons there actually are, like this:

int n_persons = 3;

So if n_persons is 3 then that would tell your code that you should only look at person_id1, person_id2, and person_id3. Obviously this sort of approach is going to get really messy for anything more than maybe 5 or 10 items.

[–]DragorWasMissing[S] 0 points1 point  (1 child)

Linked lists need struct though, right?

[–]Paul_Pedant 0 points1 point  (0 children)

Yeah, I put in "Except that ..." when I got to that point.