By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,975 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,975 IT Pros & Developers. It's quick & easy.

Pause a program while running

P: n/a
Hi!

I am running a C program and need to pause the program and change some
of the variables. Is there any function that checks if there is a
character in the Standard Input Buffer, else the program keeps on
running. Can someone please help me on that.

AN
Nov 14 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
am********@yahoo.com (Amit Nath) wrote in
news:17**************************@posting.google.c om:
Hi!

I am running a C program and need to pause the program and change some
of the variables. Is there any function that checks if there is a
character in the Standard Input Buffer, else the program keeps on
running. Can someone please help me on that.


No, not like I think you want. You'll need to find some platform-specific
function supplied by your compiler to "poll" for an input char. Such
functions are off-topic here, e.g. kbhit() for MS-DOS.

--
- Mark ->
--
Nov 14 '05 #2

P: n/a
In <Xn********************************@130.133.1.4> "Mark A. Odell" <od*******@hotmail.com> writes:
am********@yahoo.com (Amit Nath) wrote in
news:17**************************@posting.google. com:
I am running a C program and need to pause the program and change some
of the variables. Is there any function that checks if there is a
character in the Standard Input Buffer, else the program keeps on
running. Can someone please help me on that.


No, not like I think you want. You'll need to find some platform-specific
function supplied by your compiler to "poll" for an input char. Such
functions are off-topic here, e.g. kbhit() for MS-DOS.


Using a debugger is probably a better option in the first place, as it
doesn't require any changes in the program.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3

P: n/a
Da*****@cern.ch (Dan Pop) wrote in news:cb**********@sunnews.cern.ch:

I am running a C program and need to pause the program and change some
of the variables. Is there any function that checks if there is a
character in the Standard Input Buffer, else the program keeps on
running. Can someone please help me on that.


No, not like I think you want. You'll need to find some
platform-specific function supplied by your compiler to "poll" for an
input char. Such functions are off-topic here, e.g. kbhit() for MS-DOS.


Using a debugger is probably a better option in the first place, as it
doesn't require any changes in the program.


Agreed. I had thought maybe he wanted to change variables normally input
by a user, like using the up arrow key to increase an averaging window
size or something.

--
- Mark ->
--
Nov 14 '05 #4

P: n/a
"Mark A. Odell" <od*******@hotmail.com> wrote in message news:<Xn********************************@130.133.1 .4>...
Da*****@cern.ch (Dan Pop) wrote in news:cb**********@sunnews.cern.ch:

I am running a C program and need to pause the program and change some
of the variables. Is there any function that checks if there is a
character in the Standard Input Buffer, else the program keeps on
running. Can someone please help me on that.

No, not like I think you want. You'll need to find some
platform-specific function supplied by your compiler to "poll" for an
input char. Such functions are off-topic here, e.g. kbhit() for MS-DOS.


Using a debugger is probably a better option in the first place, as it
doesn't require any changes in the program.


Agreed. I had thought maybe he wanted to change variables normally input
by a user, like using the up arrow key to increase an averaging window
size or something.

While I am running the program, I would like to change the value of a
certain variable, say 'int i', if a character, say ESC, is present in
the Standard Input. If the ESC character is present, the program would
ask the new value of 'int i', else, the program continues with the new
value of 'i'.

I am interfacing some Keithley instruments with CEC488 board and the
data acquisition process is fully automatic and goes on for 6-7 hours
without any user intervaention. As a further modification, I am trying
to change some of the variables in the program if the 'ESC' button is
pressed. I am using a bit older version of BC++ (v 3.0, 16-bit) and am
running the program from MS-DOS.
Nov 14 '05 #5

P: n/a
am********@yahoo.com (Amit Nath) wrote in
news:17**************************@posting.google.c om:
I am interfacing some Keithley instruments with CEC488 board and the
data acquisition process is fully automatic and goes on for 6-7 hours
without any user intervaention. As a further modification, I am trying
to change some of the variables in the program if the 'ESC' button is
pressed. I am using a bit older version of BC++ (v 3.0, 16-bit) and am
running the program from MS-DOS.


You are in luck then, there is an entire hierarchy of Borland newsgroups
to ask this question in. They will be able to help you "catch" the ESC key
using Borland extension to the C language. See the borland.public.*
hierarchy.

--
- Mark ->
--
Nov 14 '05 #6

P: n/a
am********@yahoo.com (Amit Nath) writes:
[...]
I am interfacing some Keithley instruments with CEC488 board and the
data acquisition process is fully automatic and goes on for 6-7 hours
without any user intervaention. As a further modification, I am trying
to change some of the variables in the program if the 'ESC' button is
pressed. I am using a bit older version of BC++ (v 3.0, 16-bit) and am
running the program from MS-DOS.


There's no portable way to do what you want in standard C, which is
what we discuss here. There is probably a non-portable way to do it.
You might try asking in comp.os.msdos.programmer. (But first consult
your documentation and/or do a web search; search for "kbhit" is
likely to be useful.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7

P: n/a
Thanks everyboby for all your help. kbhit() is a real hit and works
fine. I used kbhit() as:

(1) while (!kbhit())
{
....
// Code here
....
}
getch(); // To clear the keyboard input buffer

(2) if (kbhit())
{
....
// Change program parameters
....
getch();
}

Thanks once again,

AN
Nov 14 '05 #8

P: n/a
Amit Nath wrote:
Thanks everyboby for all your help. kbhit() is a real hit and works
fine.
Anyone on comp.lang.c that suggested the nonstandard kbhit() did you a
real disservice. It is not part of the standard C language and may well
not be supplied with the next implementation of C you need to use.
Further, there are no defined semantics or syntax which hold between
various implementations of this function.

If, on the other hand, you received this off-topic information by
private e-mail, then, godamit, respond by private e-mail.
I used kbhit() as:


Who the f. cares?
Nov 14 '05 #9

P: n/a
In <40**************@earthlink.net> Martin Ambuhl <ma*****@earthlink.net> writes:
Amit Nath wrote:
Thanks everyboby for all your help. kbhit() is a real hit and works
fine.
Anyone on comp.lang.c that suggested the nonstandard kbhit() did you a
real disservice.


Helping someone getting the job done in a platform specific manner, when
*no* portable solution exists doesn't exactly qualify as a "real
disservice".
It is not part of the standard C language and may well
not be supplied with the next implementation of C you need to use.
Further, there are no defined semantics or syntax which hold between
various implementations of this function.
Yet, it is the only way of getting the job done. Therefore, it is also
the best way of getting the job done.
If, on the other hand, you received this off-topic information by
private e-mail, then, godamit, respond by private e-mail.


Agreed.
I used kbhit() as:


Who the f. cares?


Other people, confronted with the same problem, on the same (or similar)
implementations.

Agreed, kbhit is best discussed in an MSDOS programming newsgroup, but
there is nothing intrinsically wrong with a kbhit-based solution, as long
as nothing more portable is available.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #10

P: n/a
Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<40**************@earthlink.net>...
Amit Nath wrote:
Thanks everyboby for all your help. kbhit() is a real hit and works
fine.
Anyone on comp.lang.c that suggested the nonstandard kbhit() did you a
real disservice. It is not part of the standard C language and may well
not be supplied with the next implementation of C you need to use.
Further, there are no defined semantics or syntax which hold between
various implementations of this function.


Does the C standard mandate that the usage of anything outside of it
is a sin worthy of punishment? Besides, you could wrap kbhit(), hiding
it as an implementation detail - a detail I might add which is not
covered properly by the standard.
If, on the other hand, you received this off-topic information by
private e-mail, then, godamit, respond by private e-mail.


If you make assumptions about other people's actions, then goddamnit,
take your belligerence elsewhere.
I used kbhit() as:


Who the f. cares?


The people who use newsgroups with the hope of receiving answers instead
of intimidation.
Nov 14 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.