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. |
Wrong spell it is getchar or getc (depending on weather you want to read from stdin or a file)
|
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 |
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. |
All times are GMT -5. The time now is 11:27 AM. |