我想把数据读入多数组中,再根据需要选出特定的行,要如何实现?
											 程序代码:
程序代码:#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//跳过6行
void skipline(FILE *fp, int n)  //跳过n行
{
    for (; n>0; n--)
    {
        while (fgetc(fp) != '\n');
    }
}
int main()
{
    //=====================================================
    //基本数据
    int startyear = 2005;//开始年份!!!!!
    int endyear = 2006;//结束年份!!!!!!!
    int stationID = 50136;//气象站ID号!!!!
    int N = 1;            //跳过行数
    const int number = 2;//固定值,文件特殊性质,分上下两个半年
    static int ID[125000];static int Y[125000];static int M[125000];static int D[125000];static int PRE[125000];
    static int a[125000]; static int b[125000]; static int c[125000]; static int d[125000]; static int e[125000];
    static int f[125000]; static int g[125000]; static int h[125000]; static int I[125000]; static int J[125000];
    static int k[125000]; static int l[125000]; static int m[125000]; static int n[125000]; static int o[125000];
    //======================================================
    //文件操作
    char infilename[1000];
    char outfilename[1000];
    FILE *fin, *fout;
    //写入数据
    sprintf(outfilename, "H:\\Heihe_data_all\\中国地面气候资料日值数据集(700 stations 195101-201304)\\桂江气象数据\\sunshine\\"
                            "%d.txt", stationID); //读出位置
    fout = fopen(outfilename, "w+");
    //对文件开始循环
    for (; startyear <= endyear; startyear++){
        for (int j = 1; j <= number; j++){
        sprintf(infilename, "H:\\Heihe_data_all\\中国地面气候资料日值数据集(700 stations 195101-201304)\\桂江气象数据\\"
                    "SURF_CLI_CHN_MUL_DAY_1376058268668_%d_%d.txt", startyear,j);//读入位置!!修改
        fin = fopen(infilename, "r");
        
        //跳过1行
        skipline(fin, N);
        for (int i = 0; i<125000; i++)
        {
            fscanf(fin, "%d,%d,%d,%d,%d,"
                        "%d,%d,%d,%d,%d,"
                        "%d,%d,%d,%d,%d,"
                        "%d,%d,%d,%d,%d",
                        &ID[i],&Y[i],&M[i],&D[i],&PRE[i],
                        &a[i], &b[i], &c[i], &d[i], &e[i],
                        &f[i], &g[i], &h[i], &I[i],&J[i],
                        &k[i], &l[i], &m[i], &n[i],&o[i]);
            if (stationID==ID[i])
            {
                fprintf(fout, "%10d %10d %10d %10d %10d\n", ID[i], Y[i], M[i], D[i], PRE[i]);
            }
        }
               
        fclose(fin);
       
        }
    }
   
    fclose(fout);
    return 0;
}数据格式是一个20列,122930行的txt数据,类似于如下:
站点 年 月 日 降雨 风速 温度。。。 25121 2005 1 1 100 20 20
25130 2005 1 1 20 53 19
[此贴子已经被作者于2018-11-28 08:54编辑过]



 
											





 
	    

 
	
 
											
