fscanf()的问题.... [英] Problem with fscanf()....
问题描述
该程序适用于单个记录但是对于多个记录它
没有正确读取条目...
#include< stdio.h>
#include< conio.h>
#include< stdlib.h>
#include< graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
写();
read();
getch();
}
无效写()
{
FILE * ptr;
int id;
char name [20];
float sal;
ptr = fopen(" new1.dat"," w");
printf("按控制+ z终止\ nn Id,姓名,薪水:");
scanf("%d%s%f"& id ,名称和& sal);
while(!feof(stdin))
{
fprintf(ptr,"%d% s%f",id,name,sal);
printf(" \ nIdd,Name,Salary:");
scanf("%d %S%F",&安培; ID,名称,及amp; sal);
}
fclose(ptr);
}
无效读取(无效)
{
FILE * ptr;
ptr = fopen(" new1.dat"," r");
int id2;
浮动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);
}
mo ********* @ gmail.com 写道:
#include< conio .h>
#include< graphics.h>
void main(void)
clrscr();
write();
read();
getch();
}
printf("按control + z终止\ n Id Id,Name,Salary:");
scanf("%d%s%f"& id,name& sal);
while(!feof(stdin))
你在拖钓,对吧?请告诉我你在拖钓...
Richard
rl *@hoekstra-uitgeverij.nl (Richard Bos)写道:
mo ********* @ gmail.com 写道:
> #include< conio.h>
#include< graphics.h>
> void main(void)
clrscr();
write();
read() ;
getch();
}
printf("按control + z终止\ nn Id,Name,Salary:");
scanf("% d%s%f",& id,name,& sal);
while(!feof(stdin))
你们是拖钓,对吗?请告诉我你在拖钓...
Richard
是另一个笑话的延续,或者你还在忙吗?
< mo ********* @ gmail.comwrote in message
新闻:11 ********************* @ q3g2000prf.googlegrou ps.com ...
该程序适用于单个记录但是对于多个记录它
没有正确读取条目...
#include< ; stdio.h>
#include< conio.h>
#include< stdlib.h>
#include< graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
写();
read();
getch();
}
无效写()
{
FILE * ptr;
int id ;
char name [20];
float sal;
ptr = fopen(" new1 .dat"," w");
printf("按control + z终止\ nnr Id,Name,Salary:");
scanf (%d%s%f,& id,name,& sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
fprintf(ptr,"%d %s%f \ n",id,name,sal);
您可能会想象scanf()是printf()的镜像,但事实上它是
不是。你必须告诉printf()把空格放在哪里。
>
printf(" \ nId,Name,Salary) :");
scanf("%d%s%f"& id,name& sal);
}
fclose(ptr);
}
无效读取(无效)
{
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);
}
-
免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm
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);
}
mo*********@gmail.com wrote:
#include<conio.h>
#include<graphics.h>
void main(void)
clrscr();
write();
read();
getch();
}
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))You''re trolling, right? Please tell me you''re trolling...
Richard
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
mo*********@gmail.com wrote:
>#include<conio.h>
#include<graphics.h>
>void main(void)
clrscr();
write();
read();
getch();
}
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
You''re trolling, right? Please tell me you''re trolling...
Richardis that a continuation of the other joke, or you''re just carping on still?
<mo*********@gmail.comwrote in message
news:11*********************@q3g2000prf.googlegrou ps.com...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);
fprintf(ptr, "%d %s %f\n", id, name, sal);
You might imagine that scanf() is the mirror of printf(), but in fact it is
not. You have to tell printf() where to put the spaces.
>
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);
}
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
这篇关于fscanf()的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!