欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c 读入文件 CC++C#FPJ# 

程序员文章站 2022-07-12 11:00:57
...
#include  "stdio.h"
#include "iostream.h"
void main(){
struct curveHead{
    char cg[4];
char comName[80];
char curveName[80];
//short sCurveNum;
        //short sReservation;
short sh[2];
char dls[20][4];
//short sh[2];
//float fl[3];
        //char  m_cWellName[80];
       
        //char  m_cCurveName[80];
        float StartWellDepth;
        float EndWellDepth;
        float SamplingSpace;
        int   Reservation;
        float fSampleNum;
        char  cReservation[8];
        char  cMoreCurve[220];
        //float extent[200000];

}head[1];
struct curveHead *p;
p=head;

//char ch[80];
//char extent[200000];
//char cg[4];
//char comName[80];
// char curveName[80];
//char dls[4];
FILE *fp;
//short *sh;
// short sh[2];
//float fl[3];

// FILE *fpp;
// fpp=fopen("aa","w+");
if ((fp=fopen("LACBL2","rb"))==NULL)
printf("error");
//fseek(fp,4L,0);
//cout<<"sdfgfsdgfdsgfdsgfs";
//int j=sizeof(struct curveHead);
//cout<<j;
int i=fread(p,sizeof(struct curveHead),1,fp);
cout<<p->cg;
cout<<"\n";
cout<<p->comName;
cout<<"\n";
cout<<p->curveName;
cout<<"\n";
for(int q=0;q<20;q++){
cout<<p->dls[q];
cout<<"\n";
}
cout<<"\n";
cout<<p->sh[0];
cout<<"\n";
cout<<p->sh[1];
cout<<"\n";
cout<<p->StartWellDepth;
cout<<"\n";
//cout<<p->StartWellDepth;
cout<<p->EndWellDepth;
cout<<"\n";
cout<<p->SamplingSpace;
//cout<<p->SamplingSpace;
cout<<p->Reservation;
cout<<"\n";
cout<<p->fSampleNum;
cout<<"\n";
cout<<p->cReservation;
cout<<"\n";
cout<<p->cMoreCurve;
fseek(fp,496,0);
float data[5][64];
fread(data,64*5*4,1,fp);
for(int n=0;n<5;n++)
for(int m=0;m<64;m++){
cout<<data[n][m];
cout<<"\n";
}
//cout<<p->extent[145000];
// FILE *fpp;

//if ((fpp=fopen("aaa.txt","w+"))==NULL)
// printf("error");
// fwrite(p->sh,4,1,fpp);


fclose(fp);



}