帮我看下这问题怎么解决哦。
程序代码:
#include<stdio.h> #include<stdlib.h> struct xx { int bhao; char mz[15]; float qian; float pj; }shuj[100]={0}; FILE *fp; FILE *fo; int ww; int main() { fp=fopen("data.txt","a"); fo=fopen("data1.dll","w"); void tjia(); void ckan(); int i; do { i=0; printf("1,添加数据\n2,查看数据\n"); scanf("%d",&i); switch(i) { case 1: tjia(); break; case 2: ckan(); break; } }while(i!=3); } void tjia() { int i,w; printf("请输入要添加的人数:"); scanf("%d",&w); fread(&ww,sizeof(int ww),1,fo); //好想是这里错了 ,不知道要怎么代替哦. ww=ww+w; if(fwrite(&ww,sizeof(int ww),1,fo)!=1) ; for(i=0;i<ww;i++) if(shuj[i].bhao==0) { printf("请输入编号:"); shuj[i].bhao=rand()%1000; printf("编号自动生成成功!\n"); printf("请输入名字:"); scanf("%s",shuj[i].mz); printf("请输入钱数:"); scanf("%f",&shuj[i].qian); shuj[i].pj=shuj[i].qian/3.0; if(shuj[i].bhao!=0) if(fwrite(&shuj[i],sizeof(struct xx),1,fp)!=1) printf("数据写入错误!\n"); } } void ckan() { fp=fopen("data.txt","r"); int i; for(i=0;i<100;i++) { fread(&shuj[i],sizeof(struct xx),1,fp); if(shuj[i].bhao!=0) printf("\n编号:%d,名字:%s,钱数:%.2f,平均:%.2f\n",shuj[i].bhao,shuj[i].mz,shuj[i].qian,shuj[i].pj); } fclose(fp); }
各位大神帮忙看看.
[ 本帖最后由 user_qiangzi 于 2012-6-5 15:17 编辑 ]