Mail Archives: djgpp/2001/03/07/13:30:44
--12001030719271799
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,
I am experiencing problems when using the fflush function.
I am compiling the program with both Borland C Compiler and gcc, with both
compilers no error crops up. However the BCC version works fine, whilst the
gcc version is ignoring the fflush (stdin).
Attached please find the code I am using. Am I doing something wrong =3F
I am using djgpp version 2.03 on Windows 95.
Thanks
Kenneth
--12001030719271799
Content-Type: text/plain; charset=iso-8859-1;
name="question.c"
Content-Disposition: attachment;
filename="question.c"
Content-Transfer-Encoding: quoted-printable
/*
The command line I am using to compile with gcc:
gcc -Wall -g -ansi -pedantic question.c -o question.exe
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void exit=5Ffn1(void)
{ /* Exit function called prior to exiting to OS*/
printf("\nExit function #1 called\n");
}
int main(int argc, char **argv)
{
int count; /*Counter to=20process commandline args*/
char ch; /*char to take input from user switch*/
int num; /*Where to store the=20number given by the user*/
char keynum[10]; /*Where the number is being stored (fgets)*/
atexit(exit=5Ffn1); /*setting=20up exit functions*/
printf ("\n\nChecking input switches\n");
if (argc <2) printf ("No commandline parameters given\n");
for (count =3D 1; count < argc ;count++)
{ /* Displays switch as they are */
printf ("Switch %d is %s \n",count ,argv[count]);
}
printf("Q - To Quit, A - Enter value\n");
while (1)
{
ch =3D toupper(fgetc(stdin)); /*get input from user in upper case*/
if (ch =3D=3D 'Q') break; /* To exit loop*/
switch (ch) {
case 'A': {
=20 printf ("A");=20
printf ("Enter number : ");
=20 fflush(stdin);/*Flush input strea=
m for another input*/
fgets (keynum , sizeof(keynum) , st=
din);
sscanf (keynum , "%d" , &num);
printf ("\nNumber entered is : %d", num);
printf ("\n**Number has been entered");
break;
}
default: printf("Q - To Quit, A - Enter value\n");
} /*prints menu*/
}
return 0;
}
--12001030719271799--
- Raw text -