![]() |
|
#11
|
|||
|
|||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
Hey hey hey! This thread is about this : www.gidnetwork.com/b-61.html It says one should avoid to use that command and the author is wondering why it's so popular. I'm only explainning why it is popular and the good reasons it has to be. I also say myself if you read a little more in my post that yes indeed system command should be avoided and that I know why. If you can't use the command... well it's just another flaw, I'm not defending it I'm explainning why it is popular. I'm not trying to pick a fight or anything here... I think it's unreasonnable. I'm only trying to ask for a better way to do a "Press ANY key" and not a silly replacement that will only take the key enter. Since I'm nothing but a student here I not try to be a smartass because I'm learning, not teaching. I also seek the way to do it on the internet but couldn't get it quite well. The closest thing I got to was: CPP / C++ / C Code:
It needs to include conio.h for the getch(); It might not be the best thing but hey, at least I'm getting closer to it. Oh yeah... Quote:
Well if you check that article I told you about before : www.gidnetwork.com/b-61.html It asks down below if I'd wish to comment about it. Well yes indeed I do want to comment about this article. If you leave me the possibility to comment about it when it may appears old and then bitch on me about it and tell me that asking for help is not going to help me here but that I have to search for documentation (which I waster hours and hours on doing) is what will help me well SORRY. I'm comming here before the author of this page as a student and I am trying to have a civilised conversation in which exchange of informations which might lead to a solution for the situation's problem will occur. So please, unless your post is related and helpfull toward a better situation I'm asking you to leave. I don't like talking with people that doesn't use their reasons and tell me to seek information somewhere else than on a discussion forum about programming languages such as C++. Thanks for reading. ^^ |
|||
|
#12
|
||||||
|
||||||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
...with a name like MetalWarrior, it could be easier to say that you're not trying to pick a fight had your name been Ghandi or something Quote:
The stream terminator by default is the result of the enter key being pressed. Modify the stream terminator to terminate on any character. Quote:
There is no "conio.h" in standard C or C++. It is a platform and compiler specific header. I advise against using it. The mere fact that it is still around is something to abhor. Quote:
Trust me, you're definitely NOT getting any "closer" by using conio.h in any piece of code anywhere for any reason. Quote:
...and I agree with you that you should post regardless of how old the original posting was/is. Quote:
Welcome. Ask away. MxB |
|
#13
|
|||
|
|||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
Quote:
In reference to the original post, the whole reason the system("PAUSE") issue comes up is that there exist environments where an executable is hosted in its own command window. When the executable exits, so does the hosting window. To prevent this from happening one must suspend the exit of their program in one way or another or run the command by hand (instead of double-clicking an icon or from within an IDE). Windows provides a PAUSE command that will enable a user to suspend the current command window - it is trivial to shell-out to that command to do the dirty work of pausing the program (this is what system("PAUSE") does). Realize, thought, that it is the PAUSE command that handles the input and output you see, not your program. That means that if your hosting environment doesnt support the PAUSE command, you cant do that. This topic is not new and is well debated. I question your search techniques if you could not find any relevant information on the subject. Here is the top google hit for 'portable system pause'. As an aside, the whole idea of this being an efficiency concern is likely a bit of a red herring. At any point where you are handing control to a user before continuing execution (especially directly before termination) is unlikely to be a point where you are going to be concerned with bottlenecks and resource hogs. __________________
My personal site: Utilities for text processing, debugging, testing and plotting |
|
#14
|
|||
|
|||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4To L7Sqr
Thanks... I'm sorry for beingsuch a bother so I'm going to check out some more. I learned a lot thanks to you. Also... I'm going to look any way to get the inputs from the keyboard dirrectly... Thanks again for the information. |
|
#15
|
|||
|
|||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
Ummm---If people don't realize it's a portability problem, how the heck would they know to use that in a search phrase? It's up to We Who Know about such things to bring it up, as you have very capably done. But, in my opinion, it's not fair to knock them for not knowing. See Footnote. Quote:
Also, in my opinion, adding silly arguments just makes people think that the whole issue is, well, silly, and it waters down the importance of the significant part of the message. Namely the portability factor. I mean, if it is "wrong" then explain why it is wrong in no uncertain terms and in terms that mean something to the target audience. "Expensive function?"---give us a break! On the other hand, if it is not exactly "wrong" but maybe not exactly"right" either, meaning that one has an opinion that it should be dis-recommended, then I think the arguments should be sound and consistent either from a pedagogical point of view or from a practical point of view (maybe even both). But that's just my opinion. I mean, saying that a person deserves a prison sentence because he "robbed a bank" is one thing, but adding a charge that he also deserves time in the Pokey because he "married a horse" doesn't contribute to the gravity of the matter, in my opinion. As far as a previous poster's argument about looking "professional" I have to ask (rhetorically), now that we are approaching the second decade of the 21st century and people surf the web on their mobile phones, how "professional" is a command-line program that looks just about the way that it would have looked on DOS 3.3 (or whatever) in 1986? Don't paying customers expect more? Don't get me wrong, I write command-line programs just about every day, for my own use and for embedded systems. A "professional" look is not part of the mix. The emphasis is on functionality. (You don't need to be told to, "Ignore the Man Behind the Curtain," because there is no curtain!) If I wanted a non-graphical semi-professional look, I would probably go for a (non-standard) ncurses (it even has getch()) application, but portability will still be an issue. I mean, even though the basic ncurses functions exist in libraries for Windows and for Linux machines, there are (almost) always implementation-dependent differences. Oh, yeah, another thing... The "Press any key . . . " prompt that I get from system("pause") compiled with a Borland or Microsoft compiler for my Windows xp box is kind of confusing to me. I mean, I can't even find a key marked 'any' on the keyboard! I tried a bunch of keys and I found that it doesn't respond to a 'Shift' key or a 'Ctrl' key or an 'Alt' key or the 'PrtScrn' key or the 'ScrLck' key or the 'Pause' key. Don't even get me started on 'Caps Lock' or 'Num Lock!" "Press any key," indeed! Hmph! Anyhow for people going beyond the beginning phase (or for people for whom system("pause") is not an option), they should expect to have to learn a little about how input data from a keyboard interacts with programs. (Maybe that comes in a later lesson.) As has been stated by a number of people, including yours truly (but apparently Walt hasn't "got it" yet), the reason that system("pause") is popular with people for whom it is an option is that it is easy to use and makes it easy for beginners (maybe even not-so-beginners) to run programs from their IDE without learning much about user input. I hate to repeat myself, but I am not challenging Walt's "wrong" designation with this particular statement (I do that elsewhere) or claiming it is "right." We are just trying to explain to Walt, one more time, why it is popular. The problem (from the beginner's point of view) is that there are no standard C or C++ library functions that implement the exact functionality of the desired system("pause"). Period. Full Stop. (I probably should say that again, but as I have said so very many times, I hate to repeat myself.) If I ever needed to do such a thing, I would probably change the paradigm a little and use something like: CPP / C++ / C Code:
Now if there were any characters left in the input buffer (as there would be if there had been any scanf() statements to read stuff into a numeric variable, for example), there's a little more to it; CPP / C++ / C Code:
Or some such thing. Now the user can press anything he/she wants and as many times as he/she wants. When he/she finally gets around to pressing the 'Enter' key, as he/she was instructed to do, things proceed. (Well, actually, with the setup that I am using at this moment, if I hit 'ScrLck' a couple of times the KVM switch changes the Keyboard, Video, and Mouse inputs to another computer, but that has nothing to do with system("pause") or getchar() or any other C or C++ thing. I hope you get the idea in general. I mean, other than that...) Regards, Dave P.S. I like Walt. I really do. Walt has helped lots of folks here and otherwhere. I hope my comments are taken in the spirit in which they are intended. They are, after all, only opinions. (I also know that Walt is tough. He can take it!) Footnote: "I was born not knowing, and have only had a little time to change that, here and there." ---Richard Feynman |
|
#16
|
||||||||
|
||||||||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
Quote:
I actually think I resent this paragraph as it seems to make me out as an ego that can't understand other opinions and I need to be told multiple times because I'm dense. No, it's a 5-year old post. Just because I haven't updated it to make it longer by adding all the irrelevant info ("it's easier", "it's the way teachers teach it", etc) does not mean I don't "get it." Anyway, I have no idea if I can update it. It's 5 years old after all. It's old enough for kindergarten... Anyway, I respect you too much to take it to heart, though. Knowing you, I'm sure you didn't mean quite how it reads. At least I hope I know this... Quote:
================================= Additional comments: Just because Microsludge came up with "Press any key" does not make it a standard. It is not efficient. And to people that are strictly users, Press any key to continue and Press ENTER to continue are the same. They don't really care that much. Quote:
Quote:
Come to think of it, can you name any professional programs that use the phrase "Press any key to continue" anywhere in their program? This is a serious question -- I really want to know because I can't think of any at all. Quote:
Quote:
As for posting to a ?? old thread, this is a teaching thread -- therefore open to comments and criticisms any time. It's the dubious help that's given in the main forums that are months/years too late that is frowned upon. This thread is an appropriate place for MetalWarrior's comments. ================================= Quote:
"And here he is, the one, the only... GROUCHO!" __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#17
|
||||
|
||||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
No need to kick thy self, WaltP. My MacBook has a key labeled "enter" AND "return." ![]() Return is printed in larger letters! Long live the RETURN KEY! MxB |
|
#18
|
||||||||
|
||||||||
Re: Things to Avoid in C/C++ -- system("pause"), Part 4Quote:
that said Quote:
Quote:
Quote:
Quote:
However... I may be repeating myself, but sometimes I just can't help it: I just think that mentioning its inefficiency adds bupkiss to the discussion of the use of system("pause"), and is actually distracting from the part with which I whole-heartedly agree: It's not portable. (But that's only my opinion.) Sometimes "neos" are given an assignment that requires them to use system("pause"). If they take our advice and use getchar(), it will not be possible to satisfy the assignment. I just pointed out that if you change the functionality, you should make sure that the prompt matches the functionality. I was also trying to emphasize the good point that you made in your article that using getchar() is an alternative to system("pause") that has "almost" the same functionality, but is portable. Quote:
Quote:
Quote:
Well, I'm waiting for the duck to drop down. Groucho had a line that went, "If you've heard this story before, don't stop me, because I'd like to hear it again." (Unlike me, he didn't mind repeating himself.) Regards, Dave Footnote: "Men are born ignorant, not stupid. They are made stupid by education." ---Bertrand Russel |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Things to Avoid in C/C++ -- gets() , Part 1 | WaltP | C Programming Language | 5 | 21-Jun-2007 13:13 |
| Re: Things to Avoid in C/C++ -- feof(), Part 3 | WaltP | C Programming Language | 0 | 19-Sep-2005 21:00 |
| Re: Things to Avoid in C/C++ -- fflush(stdin), Part 2 | WaltP | C Programming Language | 0 | 17-Sep-2005 21:39 |
| Web Site Optimization - the basic things | dimos31 | Search Engine Optimization Forum | 3 | 19-Jun-2005 13:00 |
| [Tutorial] Pointers in C (Part II) | Stack Overflow | C Programming Language | 0 | 27-Apr-2005 18:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The