69,371
社区成员
发帖
与我相关
我的任务
分享
fscanf(fp,"%d",&n);//你这儿都把101读出来了下边肯定出错啊。。。
while(n!=0)
{
fscanf(fp,"%d%s%d%d",&st[i].no,st[i].a,&st[i].p,&st[i].k);//上边把101都读出来了。。。
//fscanf(fp,"%d",&st[i].no);
//fscanf(fp,"%s",&st[i].a);
//fscanf(fp,"%d",&st[i].p);
//fscanf(fp,"%d",&st[i].k);
//fscanf(fp,"%d",&n);
i++;
}
fscanf(fp,"%d",&n);
while(n!=0)
{
st[i].no = n;
fscanf(fp,"%s%d%d"st[i].a,&st[i].p,&st[i].k);
//fscanf(fp,"%d",&st[i].no);
//fscanf(fp,"%s",&st[i].a);
//fscanf(fp,"%d",&st[i].p);
//fscanf(fp,"%d",&st[i].k);
fscanf(fp,"%d",&n);
i++;
}
#include <stdio.h>
FILE *stream;
struct A
{
int no;
char a[32];
int p;
int k;
};
void main()
{
A st[1];
int i = 0;
stream = fopen( "data.txt", "r+" );
if( stream == NULL )
printf( "The file fscanf.out was not opened\n" );
else
{
/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );
/* Read data back from file: */
fscanf(stream,"%d%s%d%d",&st[i].no,st[i].a,&st[i].p,&st[i].k);
/* Output data read: */
fclose( stream );
}
}
fscanf(fp,"%d%s%d%d",&st[i].no,st[i].a,&st[i].p,&st[i].k);//第二个少了个&