Posted by Morgan Terry on 1999-03-30
Hey
I have a function where I am using printf and fgets to prompt for and
get input. If I use flushall() before my printf calls, it works, but
only in Borland C++ v4.52. When I try it w/ djgpp, it complains with
"undeclared reference to 'flushall'"
I am compiling w/ the following command line: gcc -o budget.exe budget.c
If I don't use the flushall(), though, it doesn't work right. It acts
like it's skipping some of my fgets() calls, maybe an extra newline in
one of the streams?
I would like to know what buffers I need to flush(I don't want to use
flushall() if it isn't portable), and also, if anyone could point me to
a better way of prompting for and getting the input, I would be
interested in that as well.
Here is the code for my function:
void get_input(char *date, char *desc, char *price)
{
/* I would like to get rid of these, if I can */
flushall();
printf("Enter date of purchase in mm/dd/yy format: ");
fgets(date, 9, stdin);
flushall();
printf("Enter item description(up to 50 characters): ");
fgets(desc, 51, stdin);
flushall();
printf("Enter amount: ");
fgets(price, 7, stdin);
}
Thanks.
--
Morgan morgan@xxxxxxxxxxx.xxx
"Unix is user friendly - it's just picky about it's friends."
Previous post | Next post | Timeline | Home