新手求助~运行完怎么都是0?
#include "stdio.h"#include "conio.h"
struct data
{
long int zhanhao;
int year;
int month;
int day;
int cs;
}rzbfl[730];
float b[2][365];
void read()
{
FILE *fp;
int i;
if((fp=fopen("mn","rb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<730;i++)
fscanf(fp,"%ld%d%d%d%f",&rzbfl[i].zhanhao,&rzbfl[i].year,&rzbfl[i].month,&rzbfl[i].day,&rzbfl[i].cs);
fclose(fp);
}
void save()
{
FILE *fp;
int i,j;
if((fp=fopen("mn","w"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<2;i++)
{
for(j=0;j<365;j++)
fprintf(fp,"%5d ",b[i][j]);
fprintf(fp,"\n");
}
return;
}
void main()
{
int y,i,j,k;
read();
y=rzbfl[0].year;
j=0;k=0;
for(i=0;i<730;i++)
{
if(rzbfl[i].year==y)
{
b[j][k]=rzbfl[i].cs;
k++;
}
else
{
j=j+1;
k=0;
b[j][k]=rzbfl[i].cs;
y=rzbfl[i].year;
}
}
save();
}
1.rar
(2.66 KB)