1 2 3 4 5 6 7 8
|
if(repeater){
while (AnInputStream.good()) {
c = AnInputStream.get();
//this if statement is redundant, to access the while loop this has to be true
if (AnInputStream.good()) {
displayer << c;
}
}
|
to access this part in the first place (the very first while statement in readfile()) repeater has to be good (which is fine), then it has to be good for this internal while statement (redundancy). then to further access this while statement, aninputstream must be good (which is fine), then to save the information aninputstream must be good (redundancy). And then directly after this, you check if repeater is good while still inside your while statement (further redundancy). There's your 2x redundancy, a triple check of repeating, and a double check of aninputstream.
here's the thing about cin. It doesn't do type checking, so if you store a string into a variable that's supposed to be an int, you're going to have some issues. But you said this is only between you and a few friends yeah? then it shouldn't be a problem. If you're worried about professional issues later refer to this http://www.cplusplus.com/forum/articles/6046/
To your last statement, i see. I was just making sure you understood what and how you were doing what you were, not just mindlessly using code. My apologies if this insulted you, but i've seen quite a few do so and it bothers me greatly to try and help people who do this and have no care in actually learning.
I don't know how your network works, but this doesn't work on mine. Just letting you know.
I'm getting compiler errors in cases 5-8 for your first argument as not being of the type const char. I've deleted these lines as they don't pertain to the actual problem at hand (which is as i believe the program not making infinite loops and the program not continuously reading)
my specific compiler recommends not using foped(). I've never used it so i can't say you're using it wrong.
i have a feeling it's because you're trying to use the same fstream variable to open multiple different files. That's usually a big no-no, just because things can get very confusing very fast (as it kind of has here). I've separated it into different in and out files. But have tested it to work if you only use one finput var.
I edited a lot, not only the redundancies, but i made it work as well. Because of ios::trunc however it will only store one username at a time, just letting you know.
is yourname.txt stored on both the hard drive and the network? if so why? remember conciseness is very important, and redundancy is a very big no-no. if you can't think straight one day DO NOT spend that day programming, spend the time outlining what you need and how you plan on getting there. Don't spend the time programming in circles and making yourself more confused. It will only hurt you more in the long run when you ask for help or someone else has to read your code. And trust me, i was very close to just starting a new script and doing what you want myself :P I know i'm saying all this, and it might embarrass you or something, but don't be code shy, it's very important to learn how to code so other people can read it. Very little programming is done by oneself.
i took out the way you created your files, as the way you continued to use your file would create them if they weren't already made (trunc does that).
for the version i edited that did work on my computer.
http://pastebin.com/YxmD0nyg