A
Aomighty
Hi, I've been creating a simple calculator program that asks whether
you want to add, subtract, multiply or divide, asks you for input, and
then performs the calculation. Things seem to be going well enough, but
I've run into one problem. It seems when I use fgets() or gets() within
a function I wrote, it gives me no errors, but when run, doesn't pause
for input, but skips past it. I've tried running it inside main() and
it runs fine. Compiled using gcc 3.4.3.
Here's the code snippet involved. It's in a header file which is
included from main.c. If you run it, I believe that's what will happen.
char bigbuff[101];
/* The rest of the code.*/
void add(void)
{
printf("What numbers do you wish to add?\n");
setupinput();
fgets(bigbuff, sizeof(bigbuff), stdin);
}
Thanks all.
you want to add, subtract, multiply or divide, asks you for input, and
then performs the calculation. Things seem to be going well enough, but
I've run into one problem. It seems when I use fgets() or gets() within
a function I wrote, it gives me no errors, but when run, doesn't pause
for input, but skips past it. I've tried running it inside main() and
it runs fine. Compiled using gcc 3.4.3.
Here's the code snippet involved. It's in a header file which is
included from main.c. If you run it, I believe that's what will happen.
From main, it simply calls add with add().
char bigbuff[101];
/* The rest of the code.*/
void add(void)
{
printf("What numbers do you wish to add?\n");
setupinput();
fgets(bigbuff, sizeof(bigbuff), stdin);
}
Thanks all.