LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2005, 01:01 PM   #1
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32
C code fflush/fpurge/getchar problems


ok heres the source code for the greater.c program i took getchar() out and put fflush(stdin); and it didnt work than i put fpurge(stdin); and this is what im getting. in the first place with getchar() it was seeing the enter key as a choice. so i did ctrl d and it worked fine than replaced getchar with the other 2 that i said and fflush doesnt do anything the fpurge gives me that error at bottom.


Code:
#include <stdio.h>

int main()
{
	char a,b;

	printf("Which character is greater?\n");
	printf("Type a single character:");
	a=getchar();
	fpurge(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("Next time, dont type the same character twice.");
	}
	return(0);
}
Code:
[boxerboy@localhost ~]$ gcc greater.c -o greater
/tmp/cceNCLIV.o(.text+0x4e): In function `main':
greater.c: undefined reference to `fpurge'
collect2: ld returned 1 exit status
is there something im not seeing?
 
Old 08-29-2005, 01:13 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Edit again: I found one site that says to try "__fpurge()" (see section 2.2.0 of this).

Last edited by Nylex; 08-29-2005 at 01:21 PM.
 
Old 08-29-2005, 01:46 PM   #3
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
thank you it worked great i was all over the dummies site and didnt see it never thought to look for an unofficail site thanks again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getchar() satellite Programming 10 12-24-2017 01:47 PM
fflush and fsync? power123 Programming 6 11-02-2005 11:04 PM
about getchar() captainstorm Programming 6 10-11-2003 04:14 AM
fflush fuction in c jetfreggel Programming 13 12-26-2002 06:02 PM
getchar() Winter Programming 6 05-11-2002 01:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration