J
Jackie
I just want the programme to stop for a while.
Thanks.
Thanks.
Jackie said:I just want the programme to stop for a while.
Jackie said:I just want the programme to stop for a while.
Thanks.
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
Tom said:Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
Alvin said:Jackie wrote:
Do you want the program to stop until you hit enter? If so, use cin like:
string str;
cin >> str;
That will stop the program till you press the Enter key.
Tom said::
I just want the programme to stop for a while.
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
That is a *HUGE* security risk. What if I type more than 80 characters?
I suddely make your program _read my input_ into the memory that wasn't
designated for it.
No! It's _awful_. Never use it. NEVER!
V
Tom said:Tom said::
I just want the programme to stop for a while.
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
That is a *HUGE* security risk. What if I type more than 80 characters?
I suddely make your program _read my input_ into the memory that wasn't
designated for it.
No! It's _awful_. Never use it. NEVER!
V
Victor --
I believe you missed the "erroneous" part of the discussion?
The method I proposed is one I have used for years and was learned
from a C textbook. Typically I set the size of junk[] to 240
characters and use it for all types of input and output. But how do
you justify that size without other usages?
Check out the Microsoft help on gets(). You will see they use a size
of 81 for that example.
If you "get" 80 characters from a erroneous pool of xxxx characters
... what remains is (xxxx - 80) erroneous characters. I suppose those
erroneous characters are a *HUGE* security risk and they are _awful_
too. Perhaps we should destroy all computers ... the risk is just
great for mankind.
I took the effort to read several of your replies. Your knowledge of
C++ is light years beyond mine as easily observed; however, you seem
to have made yourself a self appointed cop in the group?
And your preferred solution to the original question is .... ???
Please impress me with "how" to do things better and quit slamming
folks for existing outside your definition of intelligence. Go ahead,
teach me! I can learn from you. And just maybe ... you can learn a
thing or two as well?
-- Tom
Tom said:Tom said:char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
That is a *HUGE* security risk. What if I type more than 80 characters?
I suddely make your program _read my input_ into the memory that wasn't
designated for it.
I believe you missed the "erroneous" part of the discussion?
The method I proposed is one I have used for years and was learned
from a C textbook.
If you "get" 80 characters from a erroneous pool of xxxx characters
... what remains is (xxxx - 80) erroneous characters. I suppose those
erroneous characters are a *HUGE* security risk and they are _awful_
too. Perhaps we should destroy all computers ... the risk is just
great for mankind.
I took the effort to read several of your replies. Your knowledge of
C++ is light years beyond mine as easily observed; however, you seem
to have made yourself a self appointed cop in the group?
Please impress me with "how" to do things better and quit slamming
folks for existing outside your definition of intelligence.
Go ahead,
teach me! I can learn from you. And just maybe ... you can learn a
thing or two as well?
Jacek Dziedzic said:No, not really. Try it yourself. It will stop the program
till you press _something_ and then the Enter key.
- J.
Tom said::
I just want the programme to stop for a while.
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
That is a *HUGE* security risk. What if I type more than 80 characters?
I suddely make your program _read my input_ into the memory that wasn't
designated for it.
No! It's _awful_. Never use it. NEVER!
V
Victor --
I believe you missed the "erroneous" part of the discussion?
The method I proposed is one I have used for years and was learned
from a C textbook.
Typically I set the size of junk[] to 240
characters and use it for all types of input and output. But how do
you justify that size without other usages?
Check out the Microsoft help on gets(). You will see they use a size
of 81 for that example.
Jacek said:No, not really. Try it yourself. It will stop the program
till you press something and then the Enter key.
- J.
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
Tom said:Tom wrote:
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
That is a *HUGE* security risk. What if I type more than 80 characters?
I suddely make your program _read my input_ into the memory that wasn't
designated for it.
I believe you missed the "erroneous" part of the discussion?
No, you just missed the point. He's right, it's an enormous security
risk and it's awful. You need to spend less time being defensive and
more time worrying about writing correct code.
The method I proposed is one I have used for years and was learned
from a C textbook.
Marvelous. It's wrong.
If you "get" 80 characters from a erroneous pool of xxxx characters
... what remains is (xxxx - 80) erroneous characters. I suppose those
erroneous characters are a *HUGE* security risk and they are _awful_
too. Perhaps we should destroy all computers ... the risk is just
great for mankind.
Uh, are you seriously not familiar with the concept of a buffer
overflow? You allocate an array of 80 characters, then pass that array
(as a pointer) to a function which will read in as many characters as
the user cares to type. The 81st character clobbers some random chunk
of memory, and you get undefined behavior; in many cases, this is an
easy security exploit.
I took the effort to read several of your replies. Your knowledge of
C++ is light years beyond mine as easily observed; however, you seem
to have made yourself a self appointed cop in the group?
Warning people not to heed dangerous and incorrect advice is a good
thing. Why is this personal for you?
Please impress me with "how" to do things better and quit slamming
folks for existing outside your definition of intelligence.
Nobody slammed you. The dangerous and ill-founded recommendation you
voiced received a well-deserved thrashing, but that, again, is a good
thing.
Go ahead,
teach me! I can learn from you. And just maybe ... you can learn a
thing or two as well?
Enough melodrama. This is a technical newsgroup, please make sound
technical arguments. Nobody's convinced of anything by hissy fits.
Luke
Alvin said:Do you want the program to stop until you hit enter? If so, use cin like:
string str;
cin >> str;
Alvin said:Jacek Dziedzic wrote:
In that case, getc() or getchar() will do the trick, but that's isn't C++.
That's why I suggested the cin way instead.![]()
How about a Guru's C++ style solution for pausing with/without
erroneous garbage in the input buffer?
Marcin said:std::string junk;
std::cin >> junk;
red floyd said:The problem is if the operator types something like "hello world". Then
cin >> str will read "hello", but leave the "world" out there.
Better would be:
std::string str;
std::getline(cin,str);
I just want the programme to stop for a while.
Thanks.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.