用C语言编程，用二维数组实现对坐标内点的个数的统计

0

#include <stdio.h>
#include <stdlib.h>
#define NUMROWS 30
#define NUMCOLS 50

int main()
{
int PID;
double POSX,POSY,POSZ;
int i,j,m,n;
int dx=20,dy=20;
char title[20];
int cell[NUMROWS][NUMCOLS];
int I=158,J=158;

for(i=0;i<NUMROWS;i++)
{
for(j=0;j<NUMCOLS;j++)
{
cell[i][j]=0;
}
}

FILE *fq=fopen("tecplot_1000.dat","r"), *fp=fopen("tpout.dat","w");
if (fq==NULL || fp==NULL)
{
puts("The file open failed！");
return 0;
}

printf("Start reading the title！\n");
fgets(title,20,fq);
fprintf(fp,"Title= \"MPH\"\n");
fprintf(fp,"VARIABLES=\"X\",\"Y\",\"F\"\n");
fprintf(fp,"ZONE T= \"GEO\",I=%d ,J=%d ,F=POINT\n",I,J);

printf("Read the end of the title and start reading the data！\n");
while(!feof(fq))
{
fscanf(fq,"%d %lf %lf %lf",&PID,&POSX,&POSY,&POSZ);
if(POSZ>100 && POSZ<300)
{
i=int(POSX/dx);
j=int(POSY/dy);
cell[i][j]= cell[i][j]+1;
//fprintf(fp,"%d %d %d\n",i,j,cell[i][j]); //测试发现是cell[i][j]出了问题，
//只要输出cell[i][j]，就不能输出数据。
}

}

/*for (m= 0; m<NUMROWS ; m++)
{
for(n = 0; n<NUMCOLS ; n++)
{
fprintf(fp,"%d %d %d\n",m,n,cell[m][n]);
}
}
printf("Data reading completed！\n");*/

fclose(fq);
fclose(fp);
return 0;
}

您需要登录以后才能回答，未注册用户请先注册