user-0 提问: c语言读取txt文件二维数组中的相关数据后把相关数据存入一个新文件，求大神指点

回复:
user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <math.h>  #define n    396 #define m  7  struct info {     double d1;     double d2;     int num[5]; };  int main(void) {     errno_t err0, err1;     FILE* fp0, *fp1;     if ((err0 = fopen_s(&fp0, "F:\\ a1.txt", "r")) != 0)     {         printf("Cannot open this file\n");         exit(0);     }     if ((err1 = fopen_s(&fp1, "F:\\6-0-1-0-0.txt", "w")) != 0)     {         printf("Cannot open this file\n");         exit(0);     }     int i, j;     int ret;     struct info tmp;     for (i = 0; i < n; i++)     {         for (j = 0; j < m; j++)         {             ret = fscanf_s(fp0, "%lf %lf %d %d %d %d\n", &tmp.d1, &tmp.d2, &tmp.num[0], &tmp.num[1], &tmp.num[2], &tmp.num[3], &tmp.num[4]);             if (ret == EOF)                 goto lable;             printf("%lf %lf  %d    %d    %d    %d    %d\n", tmp.d1, tmp.d2, tmp.num[0], tmp.num[1], tmp.num[2], tmp.num[3], tmp.num[4]);             if (tmp.num[0] == 6 && tmp.num[1] == 0 && tmp.num[2] == 1 && tmp.num[3] == 0 && tmp.num[4] == 0)                 fprintf(fp1, "%lf\t%lf\n", tmp.d1, tmp.d2);         }     } lable:     fclose(fp0);     fclose(fp1);     system("pause"); }

user: user-0
content: 能讲讲你的思路吗？

user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <math.h>  #define n    396 #define m  7  struct info {     double d1;     double d2;     int num[5]; };  int main(void) {     errno_t err0, err1;     FILE* fp0, *fp1;     if ((err0 = fopen_s(&fp0, "F:\\ a1.txt", "r")) != 0)     {         printf("Cannot open this file\n");         exit(0);     }     if ((err1 = fopen_s(&fp1, "F:\\6-0-1-0-0.txt", "w")) != 0)     {         printf("Cannot open this file\n");         exit(0);     }     int i, j;     struct info tmp;     for (i = 0; i < n; i++)     {         for (j = 2; j < m; j++)         {             fscanf_s(fp0, "%lf %lf %d %d %d %d\n", &tmp.d1, &tmp.d1, &tmp.num[0], &tmp.num[1], &tmp.num[2], &tmp.num[3], &tmp.num[4]);             //fscanf_s(fp0, "%d", &data[i][j]);             printf("%lf %lf  %d    %d    %d    %d    %d\n", tmp.d1, tmp.d2, tmp.num[0], tmp.num[1], tmp.num[2], tmp.num[3], tmp.num[4]);             if (tmp.num[0] == 6 && tmp.num[1] == 0 && tmp.num[2] == 1 && tmp.num[3] == 0 && tmp.num[4] == 0)                 fprintf(fp1, "%lf\t%lf\n", tmp.d1, tmp.d2);         }     }     fclose(fp0);     fclose(fp1);     system("pause"); } 借鉴一下吧。 头文件，对于系统库文件，建议用<>，自定义文件用""

user: user-2
content: 在cmd中执行以下命令： cd /d in.txt文件所在盘符和文件夹路径 find "6    0    1    0    0" in.txt >out.txt type out.txt

user: user-0
content: 比如这些数据： 2.040000    0.250000    6    0    1    0    0     2.030000    0.250000    6    0    1    0    0     2.020000    0.250000    6    0    1    0    0      2.000000    0.250000    6    0    1    0    0       1.980000    0.250000    6    0    1    0    0     1.970000    0.250000    6    0    1    0    0     把后缀为6    0    1    0    0的数据写入新的txt文件，里面的数据格式如下： 2.040000    0.250000        2.030000    0.250000      2.020000    0.250000       2.000000    0.250000           1.980000    0.250000       1.970000    0.250000

user: user-3
content: 问题不是很清楚， 写完之后的文件格式应该是什么样的

user: user-0
content: 不是很懂啊 。