发布网友 发布时间:2024-10-24 00:45
共2个回答
热心网友 时间:2024-11-06 11:32
typedef struct PDHB1
{
int JH;
int JX;
float QSSJ;
float JSSJ;
}PDHB[50];
main(int argc, char* argv[])
{
int i;
PDHB P;
FILE *file;
file=fopen("aeroinfo.txt","r");
for(i=0;i<50&&!feof(file);i++)
{
fscanf(file,"%d%d%f%f",&P[i].JH,&P[i].JX,&P[i].QSSJ,&P[i].JSSJ);//读取数据
printf("%d %d %f %f\n",P[i].JH,P[i].JX,P[i].QSSJ,P[i].JSSJ); //输出数据
}}
热心网友 时间:2024-11-06 11:31
#include<stdio.h>
struct PDHB
{
int JH;
int JX;
float QSSJ;
float JSSJ;
};
PDHB PDHBb[50];
void main()
{
int i;
FILE *file;
file=fopen("aeroinfo.txt","r");
if(!file)
{
printf("Open error\n");
return;
}
for(i=0;i<50&&!feof(file);i++)
{
fscanf(file,"%d %d %f %f",&PDHBb[i].JH,&PDHBb[i].JX,
&PDHBb[i].QSSJ,&PDHBb[i].JSSJ);//读取数据
printf("%d %d %f %f\n",PDHBb[i].JH,PDHBb[i].JX,
PDHBb[i].QSSJ,PDHBb[i].JSSJ); //输出数据
}
}
主要有两点,一是double换成float,二是fscanf中接数据时要写上取地址符号