| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1027 人关注过本帖, 1 人收藏
标题:[原创]请帮忙解决有关文件类型的一些问题
只看楼主 加入收藏
pretty1984
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-6-10
收藏(1)
 问题点数:0 回复次数:2 
[原创]请帮忙解决有关文件类型的一些问题

程序的目的是建立一个学生信息处理的程序,包括新建,浏览,和删除等操作,下面只有新建和浏览函数,但是调试时出现问题,请帮忙指教,谢谢拉

#include<stdio.h> #define size 20 struct student_type {char name[10]; int num; int math ; int eng;

}stu[size]; char filename[10];

int i; int j; char ch; FILE *fp; void new() { printf("please input the filename you want to give\n"); scanf("%s",filename); if ((fp=fopen("filename","w"))==NULL) {printf("cannot open the file\n"); return; } printf("please input the record\n"); for (i=0;i<size;i++) {printf ("the no.%d",i); printf("de jilu wei\n"); printf("xuehao"); scanf("%d",&stu[i].num) ; printf("name"); scanf("%s",stu[i].name); printf("math"); scanf("%d",&stu[i].math) ; printf("english"); scanf("%d",&stu[i].eng); ch= getchar(); printf("do you want to continue? y or n"); scanf("%c",&ch); if (ch=='n')break; }

for (j=0;j<i;j++) if( fwrite(&stu[j],sizeof(struct student_type),1,fp)!=1) printf("file write error\n");

fclose (fp) ; } void liulan() {printf("please input the name you want to liulan"); scanf("%s",filename); fp=fopen("filename","r"); for (i=0;;i++) fread(&stu[i],sizeof(struct student_type),1,fp) ; for (j=0;j<i;j++) printf("%d\n%s\n%d\n%d\n",stu[j].num,stu[j].name,stu[j].math,stu[j].eng);

fclose (fp); } main() { int i; clrscr();

for(i=0;i<=20;i++) printf(" "); printf("welcome to the student management system\n"); printf("please input the bianhao which you want to do\n"); printf(" 1.new\n"); printf(" 2.tianjia\n") ; printf(" 3.shanchu\n"); printf(" 4.chaxun\n"); printf(" 5.paixu\n"); printf(" 6.liulan\n") ; scanf("%d",&i); switch(i) {case 1:new(); break; / * case 2:tianjia(); break; case 3:shanchu();break; case 4:chaxun();break; case 5:paixu();break; */ case 6:liulan();break; }

搜索更多相关主题的帖子: 类型 文件 
2004-06-10 20:07
曦薄远
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-6-10
收藏
得分:0 

filename 不用加引号

浏览函数中读入数据的那一行

必须要加循环控制条件

否则就成死循环了

注释项的/和*必须紧接

2004-06-10 21:01
曦薄远
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-6-10
收藏
得分:0 

做到这几点后

就不会有编译和连接错误了

至于逻辑错误

不知你会不会遇到

下次再谈

2004-06-10 21:03
快速回复:[原创]请帮忙解决有关文件类型的一些问题
数据加载中...
 
   



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

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