#include #include #include int main(void) { // 入出力ファイルに利用 char inputf[255]; char outf[255]; FILE *fpi; FILE *fpo; /* * データを保存する配列、構造体の宣言 * 詳細はそれぞれのコメント文を参照の事 * なお、それぞれの項目は、FORMMBY.TXTの用語を使用している。 */ struct mesh_head { // メッシュヘッダレコード用 int mesh; // 2次メッシュコード int node; // ノード数 int line; // ライン数 int area; // エリア数 int nokori; // レコード数 }; struct area_record { // エリアレコード用 int gyousei; // データ項目コード char todouhuken[10]; // 都道府県名 char gunshi[20]; // 郡市・北海道の支庁名 char kutyou[20]; // 政令指定都市・区町村名 }; struct mesh_head syousai[100]; // メッシュヘッダレコード用の構造体 struct area_record naiyo[1000]; // エリアレコード用の構造体 int rinsetsu[5000][2]; // ラインレコード用の配列 char str[80]; // 読み込み用 char buf[80]; // 処理用 int i, j, k; // カウント用 int countMESH; // 表示位置の指定 int countLINE; // 表示位置の指定 int countAREA; // 表示位置の指定 int nagasa; // kuwariの整列用 int min, t, max; //ソート時に利用 int kuwari[5000][30]; int a[100][30]; /* 配列kuwari[][]の初期化 */ for(i=0; i<5000; i++){ for(j=0; j<30; j++){ kuwari[i][j] = 0; } } for(i=0; i<100; i++){ for(j=0; j<30; j++){ a[i][j]=0; } } /* ファイルの処理 */ printf("入力ファイル名を入力してください\n"); scanf("%s",inputf); printf("出力ファイル名を入力してください\n"); scanf("%s",outf); fpi = fopen(inputf, "r"); if ( fpi == NULL) { printf("ファイルをオープンできませんでした。\n"); return 0; } fpo = fopen(outf, "w"); if ( fpo == NULL) { printf("ファイルをオープンできませんでした。\n"); return 0; } i = 0; j = 0; k = 0; /* データの読み込み */ while ( fgets (str, 80, fpi) != NULL) { strncpy(buf, str, 2); buf[2] = '\0'; if (strcmp(buf,"M ") == 0){ //メッシュヘッドレコードの場合 strncpy(buf, str+2, 6); buf[6] = '\0'; syousai[i].mesh = atoi(buf); strncpy(buf, str+2+6+20+3, 5); buf[5] = '\0'; syousai[i].node = atoi(buf); strncpy(buf, str+2+6+20+3+5, 5); buf[5] = '\0'; syousai[i].line = atoi(buf); strncpy(buf, str+2+6+20+3+5+5, 5); buf[5] = '\0'; syousai[i].area = atoi(buf); strncpy(buf, str+2+6+20+3+5+5+5+5, 5); buf[5] = '\0'; syousai[i].nokori = atoi(buf); i++; } else if (strcmp(buf,"L ") == 0){ //ラインレコードの場合 strncpy(buf, str+2+2+2+5+6+5+1+5+1, 5); buf[5] = '\0'; rinsetsu[j][0] = atoi(buf); rinsetsu[j+1][1] = atoi(buf); strncpy(buf, str+2+2+2+5+6+5+1+5+1+5+5, 5); buf[5] = '\0'; rinsetsu[j][1] = atoi(buf); rinsetsu[j+1][0] = atoi(buf); j=j+2; } else if (strcmp(buf,"A ") == 0){ //エリアレコードの場合 strncpy(buf, str+2+2, 5); buf[5] = '\0'; naiyo[k].gyousei = atoi(buf); strncpy(buf, str+2+2+5+5+5+5+4+4, 8); buf[8] = '\0'; strcpy(naiyo[k].todouhuken, buf); strncpy(buf, str+2+2+5+5+5+5+4+4+8, 16); buf[16] = '\0'; strcpy(naiyo[k].gunshi, buf); strncpy(buf, str+2+2+5+5+5+5+4+4+8+16, 16); buf[16] = '\0'; strcpy(naiyo[k].kutyou, buf); k++; } } /* 画面上への出力 */ countMESH = i; countLINE = j/2; countAREA = k; printf("出力情報\n"); printf("メッシュヘッダレコード数は%dです。\n",countMESH); printf("ラインレコード数は%dです。\n",countLINE); printf("エリアレコード数は%dです。\n\n",countAREA); printf("-----\n"); countLINE=0; countAREA=0; for(i=0; i 0){ for(k=0; k 0){ for(k=0; k