-1
이것은 내가 지금까지 가지고있는 것입니다. 나는 파일 day.txt을 읽고 난 텍스트 파일에서 전체 라인을 얻을 수 fgets()
를 사용하여 문자열로 넣고 추출 sscanf()
을 사용라인 계산 및 C에서 구조체 배열 표시
#include "stdio.h"
#include "stdlib.h"
#define MAX_LINE_LENGTH
struct earthquake_t{
float lat;
float lng;
float dep;
float mag;
};
FILE* fid;
int main(void)
{
double lat,lng dep,mag;
double userminlat,userminlng,usermaxlat,usermaxlng,minlat,minlng,maxlat,maxlng,i, ch,line;
struct earthquake_t *earthquake;
fid=fopen("day.txt","r");
while (!feof(fid))
{ /*Need help counting lines*/
count = fscanf(fid," %lf %lf %lf\n",&lng,&lat,&dep,&mag);
/* count tell you how many of the % fields were matched,
and you need to make sure all three were found to avoid blank lines*/
if (count ==3)
{
line ++;
}
}
fseek(fid,1,SEEK_SET);
print("%d\n",sizeof(struct earthquake_t));
earthquake = (struct earthquake_t *)malloc(sizeof(struct earthquake_t)*line);
for (i=0;i<line;i++)
{
fscanf("fid,%lf %lf %lf\n",&lng,&lati,&elevi)
earthquake[i].lat=lat;
earthquake[i].lng=lng;
earthquake[i].dep=dep;
earthquake[i].mag=mag;
/*Setting the min and max values for latitude and longatidue*/
if(earthquake[i].lng >maxlng)
{
maxlng = earthquake[i].lng;
}
if(earthquake[i].lng >minlng)
{
minlng = earthquake[i].lng;
}
if(earthquake[i].lat >maxlat)
{
maxlat = earthquake[i].lat;
}
if(earthquake[i].lat >minlat)
{
minlat = earthquake[i].lat;
}
}
좋은 직장 ... 당신이 직면하고있는 문제가 무엇인지 말해 줄 수 있습니까? – Pradheep