Pause a program while running

A

Amit Nath

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
 
M

Mark A. Odell

(e-mail address removed) (Amit Nath) wrote in

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.
 
D

Dan Pop

In said:
(e-mail address removed) (Amit Nath) wrote in



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
 
M

Mark A. Odell

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.
 
A

Amit Nath

Mark A. Odell said:
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.
 
M

Mark A. Odell

(e-mail address removed) (Amit Nath) wrote in

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.
 
K

Keith Thompson

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.)
 
A

Amit Nath

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
 
M

Martin Ambuhl

Amit said:
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?
 
D

Dan Pop

In said:
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.


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
 
W

Wynand Winterbach

Martin Ambuhl said:
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.
Who the f. cares?

The people who use newsgroups with the hope of receiving answers instead
of intimidation.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top