On Fri, 2003-12-12 at 14:04, Wesley J Landaker wrote: > On Friday 12 December 2003 11:38 am, Aryan Ameri wrote: > > Hi There: > > > > I am a first year CS student, learning C. A while ago I was asked > > this question from a fellow friend of mine: > > > > "Write a program, which promts the uset to enter some numbers. The > > user should terminate the sequence of numbers by entering EOF > > character. The program should put numbers entered by the user in to a > > 1D array". > > Hmmm... sounds a lot like a homework problem... =) >
Yes, it does... :) > Of course, the normal way to do something like this is to not use C, > since it's way more low-level than you need. But since the OP did say he was a CS major, I'd imagine that the whole point would be to do it in a very low level language. :) > It would be better to allocate memory in chunks, or better yet, do > something like read the numbers into a linked-list and then copy them > to an array when you're ready to use them that way, or to use C++ and > use the <vector> class, or something like that. I definitely agree with the linked-list suggestion. I had thought that most intro CS courses already cover linked list implementations. Either way, if you haven't had linked lists as part of your curriculum yet, learn how to do them now and it will put you ahead of the game for a lot of your courses. The course that I took that introduced linked lists took the better part of the semester to cover them though, in my opinion, one or two labs max would have been sufficient. And I wouldn't even bother putting the linked list into an array in the first place. If you write a good linked list implementation (which, as I said, would be a good exercise) it will already support all of the functions that you're likely to need with an array, so you might as well just keep it as a linked list. -- Alex Malinovich Support Free Software, delete your Windows partition TODAY! Encrypted mail preferred. You can get my public key from any of the pgp.net keyservers. Key ID: A6D24837
signature.asc
Description: This is a digitally signed message part