| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 385 人关注过本帖
标题:[讨论]看看哪里错了
只看楼主 加入收藏
oヤ偽妳變壞
Rank: 2
等 级:新手上路
威 望:4
帖 子:2251
专家分:0
注 册:2006-3-19
收藏
 问题点数:0 回复次数:2 
[讨论]看看哪里错了
#include<stdio.h>
#define SIZE 2
struct stud_sub
{
char name[10];
char grade[10];
char college[10];
char zhuanye[10];
}sub[SIZE];
void save()
{
FILE*fp;
int i;
if((fp=fopen("sub_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
printf("please enter the mat collations:\n");
scanf("%s%s%s%s%s",sub[i].name,sub[i].col_stud,sub[i].college,sub[i].zhuanye);
}
fclose(fp);
}
void check()
{
int i,j,m,n;
char a[10],b[10],c[10],d[10];
FILE*fp;
printf("please enter four charactors:\n");
scanf("%s%s%s%s",a,b,c,d);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{
fread(&sub[i],sizeof(struct stud_sub),1,fp);
m=(strcmp(sub[i].col_stud,a))||(strcmp(sub[i].grade,b));
n=(strcmp(sub[i].college,c))||(strcmp(sub[i].zhuanye,d));
j=n||m;
if(!j)
{
printf("the subject name:\n");
printf("%s\n",sub[i].name);
}
}
fclose(fp);
}
void change()
{
int i;
char a[10],b[10],c[10];
FILE*fp;
printf("please enter the subject name:\n");
scanf("%s",a);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{ fread(&sub[i],sizeof(struct stud_sub),1,fp);
if(!strcmp(sub.name,a))
{
printf("the four charactors are:\n");
printf("%s%s%s%s\n",sub[i].col_stud,sub[i].grade,sub[i].college,sub[i].zhuanye);
printf("please input what you want to change:b and c:\n");
scanf("%s%s",b,c);
strcpy(sub[i].college,b);
strcpy(sub[i].college,c);
}
}
save();
}
viod run()
{
char a[10]="check",b[10]="change",m[10];
printf("what do you want to do?please enter check or change:\n");
scanf("%s",m);
if(!strcmp(a,m))
{
printf("checking begin:\n");
check();
}
if(!srtcmp(b,m))
{
printf("changing begin:\n");
change();
}
}
main()
{
if(fopen("sub_list","rb")==NULL)
make();
else run();
}

2006-05-17 12:25
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
错太多了,例如: void拼成了viod,没有加 include "string.h"等等,编译的时候好好看看着些错应该能自己改掉的。

http://myajax95./
2006-05-17 14:59
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 

#include<stdio.h>
#include<string.h>
#define SIZE 2
struct stud_sub
{
char name[10];
char grade[10];
char college[10];
char zhuanye[10];
} sub[SIZE];

void save()
{
FILE*fp;
int i;
if((fp=fopen("sub_list","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
printf("please enter the mat collations:\n");
scanf("%s%s%s%s%s",sub[i].name,sub[i].grade,sub[i].college,sub[i].zhuanye);
}
fclose(fp);
}

void check()
{
int i,j,m,n;
char a[10],b[10],c[10],d[10];
FILE*fp;
printf("please enter four charactors:\n");
scanf("%s%s%s%s",a,b,c,d);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{
fread(&sub[i],sizeof(struct stud_sub),1,fp);
m=(strcmp(sub[i].name,a))||(strcmp(sub[i].grade,b));
n=(strcmp(sub[i].college,c))||(strcmp(sub[i].zhuanye,d));
j=n||m;
if(!j)
{
printf("the subject name:\n");
printf("%s\n",sub[i].name);
}
}
fclose(fp);
}

void change()
{
int i;
char a[10],b[10],c[10];
FILE*fp;
printf("please enter the subject name:\n");
scanf("%s",a);
fp=fopen("sub_list","rb");
for(i=0;i<SIZE;i++)
{ fread(&sub[i],sizeof(struct stud_sub),1,fp);
if(!strcmp(sub[i].name,a))
{
printf("the four charactors are:\n");
printf("%s%s%s%s\n",sub[i].name,sub[i].grade,sub[i].college,sub[i].zhuanye);
printf("please input what you want to change:b and c:\n");
scanf("%s%s",b,c);
strcpy(sub[i].college,b);
strcpy(sub[i].college,c);
}
}
save();
}

void run()
{
char a[10]="check",b[10]="change",m[10];
printf("what do you want to do?please enter check or change:\n");
scanf("%s",m);
if(!strcmp(a,m))
{
printf("checking begin:\n");
check();
}
if(!strcmp(b,m))
{
printf("changing begin:\n");
change();
}
}

main()
{
if(fopen("sub_list","rb")==NULL)
make();//找不到该函数的定义。
else run();
}


落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-05-17 15:24
快速回复:[讨论]看看哪里错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023460 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved