空行の判定
Posted: 2018年7月21日(土) 10:39
#include <stdio.h>
#define N 20
#define M 5
typedef struct plane_map {
double longitude; /* [deg] */
double latitude; /* [deg] */
} PLANE_MAP_TYPE;
int main(void){
FILE *fp_p;
const char plane_map[] = "test.txt";
int i;
PLANE_MAP_TYPE a;
fp_p = fopen( plane_map , "r");
char date1[N];
char date2[N];
for(i=0;i<M;i++){
fgets(date1,N,fp_p);
if(date1[0]!='\n'){
sscanf(date1, "%lf%lf", &a.longitude, &a.latitude);
printf("%.2f %.2f\n", a.longitude, a.latitude);
}
if(date1[0]=='\n'){
printf("\n");
}
}
return 0;
}
/*
3行目を空白にしたいのに
なぜか3行目が2行目をコピーしてしまいます
実行結果を以下に記す
12.00 12.00
11.00 11.00
11.00 11.00
20.00 20.00
30.00 30.00
ファイル(test.txt)は以下に記す
12 12
11 11
20 20
30 30
*/
#define N 20
#define M 5
typedef struct plane_map {
double longitude; /* [deg] */
double latitude; /* [deg] */
} PLANE_MAP_TYPE;
int main(void){
FILE *fp_p;
const char plane_map[] = "test.txt";
int i;
PLANE_MAP_TYPE a;
fp_p = fopen( plane_map , "r");
char date1[N];
char date2[N];
for(i=0;i<M;i++){
fgets(date1,N,fp_p);
if(date1[0]!='\n'){
sscanf(date1, "%lf%lf", &a.longitude, &a.latitude);
printf("%.2f %.2f\n", a.longitude, a.latitude);
}
if(date1[0]=='\n'){
printf("\n");
}
}
return 0;
}
/*
3行目を空白にしたいのに
なぜか3行目が2行目をコピーしてしまいます
実行結果を以下に記す
12.00 12.00
11.00 11.00
11.00 11.00
20.00 20.00
30.00 30.00
ファイル(test.txt)は以下に記す
12 12
11 11
20 20
30 30
*/