Re: Problem with fscanf()....
- From: Frodo Baggins <frodo.drogo@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 14:57:24 -0000
On Aug 31, 11:40 am, mohdalib...@xxxxxxxxx wrote:
the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
write();
read();
getch();}
void write()
{
FILE *ptr;
int id;
char name[20];
float sal;
ptr=fopen("new1.dat","w");
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
}
void read(void)
{
FILE *ptr;
ptr=fopen("new1.dat","r");
int id2;
float sal2;
char name[20];
while(!feof(ptr))
{
fscanf(ptr,"%d%s%f",&id2,name,&sal2);
printf("%d %s %f\n",id2,name,sal2);
}
fclose(ptr);
}
BAD indentation!
<OT>
Run ``indent <c-file-name> -ts4 -i4 -bli0'' on your code
</OT>
Regards,
Frodo B
.
- References:
- Problem with fscanf()....
- From: mohdalibaig
- Problem with fscanf()....
- Prev by Date: Re: Macro inside a string
- Next by Date: Re: size_t problems
- Previous by thread: Re: Problem with fscanf()....
- Next by thread: Sequence pointers
- Index(es):
Relevant Pages
|