Ok so I am working on a hash map but I ran into trouble with reading in the input. I need to be able to read in the input from a file if specified if not from the console. Thats not a problem but when it comes to reading it in from the console I am stuck.

the format for the information is as follows:
A <INT> <CHAR> <STRING> <INT> <DOUBLE>
B <INT> <CHAR> <INT>
C <INT> <CHAR> <INT> <STIRNG>
etc...

ok so I can read in 1 line perfectly fine and I can use a switch statement to detect if its a, b or c and then adjust my scanf to fit the situation.

The problem I am having is the multiple lines, I have no idea how to keep reading in the lines. I do not know if my input will be 2 lines long or 2000 lines long.

If you can read it from a file, you should be able to read it from stdin, since stdin is a "file", as is everything. The question becomes, "How do I know when I am done?" You know when you are done in the file somehow. You need to have some way of telling the user to enter "done" when entering data. It could even be "Enter 'done' when done.\n". Perhaps in the file you simple read from beginning to end. That will work with a file, but since stdin never "ends", you either need to be able to figure it out from the input or the user has to tell you. You need to tell the user how to signify that.

Is that the issue?

can you post the code with which you are working with. so that at least i can understand to upgrade it???

Well yes with the file I am able to navigate to the end of the file and thats how I know when I am done. But the thing is this is graded using an autograder and there is no way for me to "specify" that the input is done and it doesn't mention anything about a way to tell its done inputting.

Edited 4 Years Ago by akaicewolf: n/a

Well perhaps you need to create one yourself? Without seeing the spec / requirements, it's hard to say. If it's run through an auto-grader, that means there is no human typing things in, so where does the console input come from? Somehow you have to know when to stop or you have to figure out when you have "enough" input to do the job or you have to know when there is no more input.

This article has been dead for over six months. Start a new discussion instead.