亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

網點數據類型轉換為中轉型EXCLE格式

標簽:
C
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
//=====================================================
//基本数据

    const int startlon = 9755;//起始经度(97.55*100)
    const int startlat = 3995;//起始纬度
    const int xrolls = 2; //行数
    const int yrolls = 4;//列数
    const int step = 10;//步长(0.1*100)
    const int filenumber = 3;//文件总个数
    float data[xrolls][yrolls];

//======================================================
//文件操作
    char infilename[100];
    FILE* fout,*fin;
    fout = fopen("F:\\2017C\\test.txt", "a+");
    int dlon, dlat;
    //对纬度,对经度循环
    for (dlat = 0; dlat < xrolls; dlat++){
        for (dlon = 0; dlon <yrolls; dlon++){

            float lon = (dlon*step + startlon)*0.01;
            float lat = (dlat*step + startlat)*0.01;
            fprintf(fout, "%6.2f""%6.2f", lon, lat);

            //对文件开始循环
            for (int filecount = 1; filecount <= filenumber; filecount++){

                sprintf(infilename, "F:\\2017C\\test%d.txt", filecount);//读入位置!!修改

                fin = fopen(infilename, "r");
                if (!infilename){
                    printf("could not open file!");
                    exit(99);
                }

                //读入数据
                while (!feof(fin))
                {

                    for (int i = 0; i < xrolls; i++){   //i<行数
                        for (int j = 0; j < yrolls; j++){   //j<列数
                            fscanf(fin, "%f", &data[i][j]);
                        }
                    }

                }

                //写入数据
                if (filecount == filenumber)fprintf(fout, "%6.2f\n", data[dlat][dlon]);//如果是横排最后一个,则输入回车
                else fprintf(fout, "%6.2f", data[dlat][dlon]);//(行,列)==(纬度,经度)

                fclose(fin);
            }
        }
    }

        fclose(fout);
        return 0;

}
1.11    2.22    3.33    4.44
5.55    6.66    7.77    8.88
//testx.txt

//lon lat Jan Feb Mar............
97.55 39.95 0.00 1.11 3.11
97.65 39.95 1.00 1.22 3.22
97.75 39.95 2.00 1.33 3.33
97.85 39.95 3.00 1.44 3.44
97.55 40.05 4.00 2.11 3.55
97.65 40.05 5.00 2.22 3.66
97.75 40.05 6.00 2.33 3.77
97.85 40.05 7.00 2.44 3.88
//test.txt

點擊查看更多內容
2人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消