A
alien
i use gcc in ubuntu.
My problem is that, when i use getchar() twice to read a single
character each time, it doesn't stop up and asks for a new character
at second time.
The two codes i use(fflush/fpurge) is:
#include <stdio.h>
int main()
{
char a,b;
printf("Which character is greater?\n");
printf("Type a character: ");
a=getchar();
fflush(stdin);
printf("Type another character: ");
b=getchar();
if(a>b) {
printf("'%c' is greater than '%c'\n",a,b);
}
else if(b>a) {
printf("'%c' is greater than '%c'\n",b,a);
}
else {
printf("Dont type the same character twice.\n");
}
return 0;
}
which says when i type 7 once:
Which character is greater?
Type a character: 7
Type another character: '7' is greater than '
'
And the other code with fpurge(stdin) says when i want to compile it:
/tmp/ccia6orp.o: In function `main':
greater1.c
.text+0x3a): undefined reference to `fpurge'
collect2: ld returned 1 exit status
What am i doing wrong?
My problem is that, when i use getchar() twice to read a single
character each time, it doesn't stop up and asks for a new character
at second time.
The two codes i use(fflush/fpurge) is:
#include <stdio.h>
int main()
{
char a,b;
printf("Which character is greater?\n");
printf("Type a character: ");
a=getchar();
fflush(stdin);
printf("Type another character: ");
b=getchar();
if(a>b) {
printf("'%c' is greater than '%c'\n",a,b);
}
else if(b>a) {
printf("'%c' is greater than '%c'\n",b,a);
}
else {
printf("Dont type the same character twice.\n");
}
return 0;
}
which says when i type 7 once:
Which character is greater?
Type a character: 7
Type another character: '7' is greater than '
'
And the other code with fpurge(stdin) says when i want to compile it:
/tmp/ccia6orp.o: In function `main':
greater1.c
collect2: ld returned 1 exit status
What am i doing wrong?