求助啊 C语言文件该怎么操作啊

来源:百度知道 编辑:UC知道 时间:2024/05/16 12:07:01
从键盘上输入某宿舍楼6户的某月水电消耗量以及标准的水电费.计算各个用户应该缴纳的水电费.数据要求如下:水费1.5元/吨,电费0.5元/度.
住户地址 用水量/吨 用电量/度
101 5 150
201 4 90
301 4 120
401 3 78
501 5 60
601 6 105

按下面的组织形式 书写在input.dat中
1.5 0.5
101 5 150
102 4 90
103 4 120
104 3 78
105 5 60
106 6 105
要求是程序从 input.dat 中读取上面的数据(注意下 住户的no.是反过来的).
分别计算 水电费总和.
汇总全部住户的水电费
按 以下 的格式写入output.dat
住户地址 用水量 水费 用电量 电费 合计
101 5 7.5 150 75 82.5
201 4 6 90 45 51
301 4 6 120 60 66

#include<stdio.h>
#include<string.h>
#define N 6
char* ssssss(char* szT)
{
if ( !szT ) return NULL;
int i = strlen(szT), j, k;
int t = !(i%2)? 1 : 0;
for(j = i-1 , k = 0 ; j > (i/2 -t) ; j--) {
char ch = szT[j];
szT[j] = szT[k];
szT[k++] = ch;
}
return szT;
}

int main()
{
struct zdk_t {
char * a01;
double ter_cs;
double ter_cft;
double z475_cs;
double z475_cft;
double T4z_cft;
} zdk[N], *p;
int i;
double ter_pis, z475_pis;
double T4z_ter_cs = 0.0;
double T4z_ter_cft = 0.0;
double T4z_z475_cs = 0.0;
double T4z_z475_cft = 0.0;
double T4z_cft = 0.0;
FILE *fin = fopen("input.dat", "rt");
FILE *fout = fopen("output.dat", "wt");
fscanf(fin, "%lf%lf", &ter_pis, &z475_pis);