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-28-2004, 09:47 AM   #1
shams
Member
 
Registered: Jan 2004
Posts: 400

Rep: Reputation: 30
Unhappy error coding for record I/O in files


hi,
this is a code for record I/O in files:
#include <stdio.h>
main()
{
FILE *fp;
char another='Y';
struct tmp
{
char name[40];
int age;
float bs;
};
struct tmp e;

fp=fopen("emmloyee.txt","w");
if(fp==NULL)
{
puts("Cannot open file\n");
exit(0);

}
while(another=='Y')
{
printf("Enter name,age and salary of employees\n");
scanf("%s%d%f",e.name,&e.age,&e.bs);
fprintf(fp,"%s%d\f",e.name,e.age,e.bs);

printf("Another record Y/N");
fflush(stdin);
another=getche();

}
fclose(fp);
}
and this is the compilation error:
[root@localhost i-o]# gcc -o l355 l355.c
/root/tmp/ccF5ymx6.o(.text+0xcd): In function `main':
: undefined reference to `getche'
collect2: ld returned 1 exit status
this is the error anywhere the getch() or getche() are used plz tell me
how i
can solve this problem.

Last edited by shams; 08-28-2004 at 09:48 AM.
 
Old 08-28-2004, 09:59 AM   #2
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
Wrong spell it is getchar or getc (depending on weather you want to read from stdin or a file)
 
Old 08-28-2004, 10:19 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Like lone_nut said, getch() and getche() aren't standard C functions.

Another thing is, fflush(stdin) has undefined results. fflush() is only guaranteed to work with output streams, not input. Here's some more information on it: http://faq.cprogramming.com/cgi-bin/...&id=1043284351
 
Old 08-29-2004, 09:47 PM   #4
shams
Member
 
Registered: Jan 2004
Posts: 400

Original Poster
Rep: Reputation: 30
hi,
thanks for reply,i changed the getche() to getchar() ,the problem is now the program is ending with the first netry not asking for the another entry.
 
  


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
error coding structure in c shams Programming 9 08-24-2004 10:02 AM
error coding string in c shams Programming 1 08-23-2004 09:01 PM
error coding string in c shams Programming 2 08-20-2004 05:44 AM
error coding a function in c shams Mandriva 1 07-28-2004 12:09 AM
error coding a funtion in c shams Programming 2 07-27-2004 09:47 PM


All times are GMT -5. The time now is 01:54 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration