操作系统文件操作实验

上传人:E**** 文档编号:118456745 上传时间:2019-12-15 格式:DOC 页数:9 大小:522KB
返回 下载 相关 举报
操作系统文件操作实验_第1页
第1页 / 共9页
操作系统文件操作实验_第2页
第2页 / 共9页
操作系统文件操作实验_第3页
第3页 / 共9页
操作系统文件操作实验_第4页
第4页 / 共9页
操作系统文件操作实验_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《操作系统文件操作实验》由会员分享,可在线阅读,更多相关《操作系统文件操作实验(9页珍藏版)》请在金锄头文库上搜索。

1、上机实验报告南京工程学院上机实 验 报 告 课 程 名 称: 操作系统 实验项目名称: 文件操作 学生班级: 学生学号: 学生姓名: 指导教师: 实 验 时 间: 实 验 地 点: 信息楼专业机房 实验成绩评定: 2016-2017-1学期1- 3 -一、实验目的及内容在掌握文件的概念和文件管理功能后,通过实验进一步了解文件的组织结构以及常规操作,从而了解文件的实际应用,为大量信息处理问题提供一种实用有效的管理模式。内容:创建一个新文件,文件内容为本班所有同学的学号、姓名、操作系统课程成绩,要求采用有格式的存储格式;文件建立之后,能够对文件进行插入、删除、查找等操作。二、实验相关知识简介文件系

2、统提供给用户程序的一组系统调用,如文件的建立、打开、关闭、撤消、读、写和控制等,通过这些系统调用用户能获得文件系统的各种服务。不同的系统提供给用户不同的对文件的操作手段,但所有系统一般都提供以下关于文件的基本操作:1对整体文件而言(1)打开(open)文件,以准备对该文件进行访问。(2)关闭(close)文件,结束对该文件的使用。(3)建立(create)文件,构造一个新文件。(4)撤消(destroy)文件,删去一个文件。(5)复制(copy)文件,产生一个文件副本。2对文件中的数据项而言(1)读(read)操作,把文件中的一个数据项输入给进程。(2)写(write)操作,进程输出一个数据项

3、到文件中去。(3)修改(update)操作,修改一个已经存在的数据项。(4)插入(insert)操作,添加一个新数据项。(5)删除(delete)操作,从文件中移走一个数据项。 三、设计思路及关键程序代码分析#include #include #include int NUM = 0; struct student char num20; / 学号 char nam20; / 姓名 int score; / 成绩 struct student * next; ; typedef struct student Stu; typedef Stu * STU; void SaveConf(STU h

4、ead); void Menu(STU head); void Choose(STU head); void LoadConf(STU head); void Create(STU head); void Init(STU *head) /头节点初始化 (*head) = (STU)malloc(sizeof(Stu); (*head)-next = NULL; void LoadConf(STU head) /从文件加载信息至链表 int i = 1; FILE *fp; STU newstu; STU p= head; fp = fopen(text.txt,r+); if(fp = NU

5、LL) printf(文件不存在!已为您创建新文件!n); fp = fopen(text.txt,a+); while(i 0) newstu = (STU)malloc(sizeof(Stu); i = fscanf(fp,%s %s %dn,newstu-num,newstu-nam,&newstu-score); if(i = -1) free(newstu); newstu = NULL; break; p = head; while(p-next != NULL) p = p-next; p-next = newstu; newstu-next = NULL; p = NULL;

6、fclose(fp); void Create(STU head) /插入信息 STU newstu; STU p = head; newstu = (STU)malloc(sizeof(Stu); printf(请输入学号:); scanf(%s,newstu-num); printf(请输入姓名:); scanf(%s,newstu-nam); printf(请输入成绩:); scanf(%d,&newstu-score); while(p-next != NULL) p = p-next; p-next = newstu; newstu-next = NULL; char flag; g

7、etchar(); printf(是否继续插入信息(y or n):); scanf(%c,&flag); if(flag=y) Create(head); else Choose(head); void SaveConf(STU head) /保存信息到文件 FILE *fp; STU p = head-next; fp = fopen(text.txt,w); if(fp = NULL) printf(打开文件失败!n); return; while(p != NULL) fprintf(fp,%s %s %dn,p-num,p-nam,p-score); /写入数据到文件中 p = p-

8、next; fclose(fp); STU search(STU head,char *s) /删除 STU p; p = head-next; while(p != NULL) if(strcmp(s,p-num) = 0) return p; p = p-next; return p; void Delete(STU head) STU p; STU q = head; char flag; char n20; printf(请输入需要删除学生的学号: ); scanf(%s,&n); p = search(head,n); if(p = NULL) getchar(); printf(您

9、输入的学号不存在,请重新输入: ); scanf(%c,&flag); Delete(head); else getchar(); printf(%s %s %dn,p-num,p-nam,p-score); q = head; while(q-next != p) q = q-next; q-next = p-next; p-next = NULL; free(p); p = NULL; printf(delete success!n); Choose(head); void Constant(STU head) /查找 STU p = head; char number20;int fin

10、d=0; printf(请输入需要查找学生的学号:); scanf(%s,number); while(p != NULL) if(strcmp(number,p-num) = 0) printf(查找结果如下:n); printf(%s %s %dn,p-num,p-nam,p-score); find=1; p = p-next; if(find=0)printf(您输入的学号不存在!); getchar(); Choose(head); void Menu(STU head) printf(t*文件管理*tn); printf(t*1.插入信息*tn); printf(t*2.删除信息*tn); printf(t*3

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号