linux编程术及源代码.docVIP

  • 9
  • 0
  • 约7.37千字
  • 约 6页
  • 2016-10-18 发布于贵州
  • 举报
linux编程术及源代码

西 安 邮 电 大 学 (计算机学院) 课内实验报告 实验名称: Linux编程技术 专业名称: 软件工程 班 级: 学生姓名: 学号(8位): 指导教师: 实验日期: 2014年9月日 二. 实验内容 1.上机练习理论课程中讲过的命令 2.上机练习使用tar 3.练习使用vim和gcc,编程实现下面的问题。 建立一个结构体数组in,输入10名学生的姓名、班级三门课程的成绩。将这些信息写入文件info.txt中,随后将文件中的信息读入数组out 4.编程实现自己的error函数 5.使用gdb调试下面的程序: #include stdio.h int main() { int a[5][6], *p, i, j; for (i = 0; i 5; i++){ for (j = 0; j 6; j++){ scanf(%d, a[i] + j); } } p = a; for (i = 0; i 5 * 6; i++){ printf(%d , *p+i); } return(0); } 方案设计 查询Linux手册掌握和运用一些学过的基本命令 在Linux环境下,熟练操作环境 温习所学过的数组,文件等所学过的知识对文件进行编译 学会Gdb的基本调试 t编程: #includestdio.h #includestring.h #includemalloc.h #includestdlib.h #define PT %s\t%s\t%d\t%d\t%d\n,stu-name,stu-grade,stu-score1,stu-score2,stu-score3 typedef struct in { char name[20]; char grade[20]; int score1; int score2; int score3; struct in *next; }in; in *creat() { in *head,*r,*stu; head=(in *)malloc(sizeof(in)); /*创建头结点*/ head-next=NULL; r=head; int i; for(i=1;i=10;i++) { stu=(in *)malloc(sizeof(in)); printf(\n请输入第%d个学生的信息:,i); printf( 姓名,班级,score1,score2,score3 ); scanf(%s%s%d%d%d,stu-name,stu-grade,stu-score1,stu-score2,stu-score3); fflush(stdin); r-next=stu; r=stu; } r-next=NULL; return (head); } int save(in *h) { in *stu; FILE *fp; fp=fopen(info.txt,wt); if(fp==NULL) { printf(\n写文件出错!); fclose(fp); exit(0); } for(stu=h-next;stu!=NULL;stu=stu-next) fprintf(fp,PT); printf(\n\t\t\t\t ^_^ 文件已成功保存!\n); fclose(fp); } read() { in *head,*r,*stu,out[10+1]; FILE *fp; fp=fopen(info.txt,rt); if(fp==NULL) /*判断文件是否存在*/ { printf(\n读文件出错,退出!\n); exit(0); } head=(in *)malloc(sizeof(in)); /*创建头结点*/ head-next=NULL; r=head; int i=1; while(!feof(fp)) /*文件未结束*/ { fscanf(fp,%s%s%d%d%d\n,out[i].name,out[i].grade,o

文档评论(0)

1亿VIP精品文档

相关文档