Thanks for the feedback. Sometimes my presentation needs work.
However, the reason I continue to post this stuff is
exactly because you are a beginner (and don't know any better).
Frankly, all those book authors and university professors teaching people to use
system() to set console colors and the like are doing you (that is, beginners) a
terrible disservice. People who claim to be your friend and instruct you to run around with knives really don't have your best interests at heart. They ought to be shot. (Along with virus writers.)
Because they know better.
Forgetting everything other than what it takes to be "easy" for beginners, there is only
one difference between
1 2 3
|
#include <stdlib.h>
system( "color 5B" );
|
and
1 2 3
|
#include <windows.h>
SetConsoleTextAttribute( GetStdHandle( STD_INPUT_HANDLE ), 0x5B );
|
The difference is the number of words you have to memorize -- or letters you have to type.
Don't complain about some extra letters. It is never too much of an inconvenience to do things the right way. (Which is the whole point.)
The bonus is: you have learned how to do something safely and quickly, you won't be treated like a loser-wannabe by other programmers, you'll be more valuable to your employer, and you'll be better able to learn and understand new things about handling the console than otherwise.
MS is a funny master. I know their website presents things using
system() as examples. But if you tried to get a job at Microsoft with such code they would be showing you out the door before it had time to close after you first entered.
Mythios himself is still a beginner. In other words, he is still learning. What he has going for himself is that he is working hard at learning new things and when he learns something new or cool -- he does something with it. When he learns something that previously perplexed him -- he posts to help others get past that same problem.
If you had cared to actually compile and run our two programs, you would have noticed that they behaved almost identically -- the difference is that I improved it some. His only ends when the user presses
Ctrl-C or otherwise kills the program. Mine ends properly by pressing any key. It also tells you how to quit and slows down the output a little bit. I also moved all those colors into an indexable array, instead of repeating the same statement over and over and over in the big loop.
Again, I appreciate the feedback; I realize that I didn't very carefully explain the improvements I made. However, the commentary really is sufficient to follow along. Programming is a very exacting discipline: it requires you to pay attention to all the little details.
Being a beginner does not mean things should be "easy". It means that you still have stuff to learn. Learn it.
If it goes over your head, and a lot of it will at first, either ignore it, or cut and paste it to use it, or study it until you understand it well. Please don't complain about it. (But please do offer suggestions on how I can better present it.) Believe it or not, just because I'm not a "beginner" doesn't mean I am not learning new stuff the same way all the time. It took me a year to wrap my head around network protocols.
Hope this helps.