大学一年级下学期C语言程序设计实验报告答案完整版 下载本文

内容发布更新时间 : 2024/5/15 0:25:06星期一 下面是文章的全部内容请认真阅读。

优秀学习资料 欢迎下载

}

while(1) {

scanf(\ if(s[i].a!='!')

s[i].num=i+1; else

break; if(s[i].a>'Z')

s[i].a=s[i].a-32;

printf(\ i++; }

(3)在本实验的实验内容1的基础上,实现在链表元素index之前插入元素的操作Insert( struct node *head, int index)和删除指定位置元素的操作Delete( struct node * head, int index),并编写主函数测试。

#include #include #include #include struct student {

char name[15]; char num[15]; char risk[15];

struct student *next; };

struct student * fun() {

struct student *p,*q,*head; q=head=NULL; char str[15]={'\\0'};

printf(\请依次输入学生的姓名,学号,成绩:(以'0'作为结束标志)\\n\

优秀学习资料 欢迎下载

while(1) {

scanf(\ if(str[0]=='0') break;

p=(struct student *)malloc(sizeof(struct student)); strcpy(p->name,str); scanf(\ scanf(\ if(head==NULL) head=q=p; else {

q->next=p; q=p; } }

q->next=NULL; return head; }

struct student * park(struct student *head) {

int i;

char str[15];

struct student *p,*q;

printf(\你想要删除某个学生的信息吗?是/否(1/0)\\n\scanf(\if(!i)

return head;

printf(\请输入你想要删除的学生姓名\\n\scanf(\

for(p=head,q=NULL;p!=NULL;q=p,p=p->next) if(!strcmp(p->name,str)) break; if(p==NULL) {

printf(\没有你要删除的学生的信息\\n\

return head; } else {

优秀学习资料 欢迎下载

if(q==NULL) head=p->next; else {

q->next=p->next; }

free(p); }

return head; }

struct student *wall(struct student *head) {

int i,j,k=1;

struct student *p,*q,*r;

printf(\你想要添加某个学生的信息吗?是/否(1/0)\\n\scanf(\if(!i)

return head;

printf(\请输入你想要添加的学生的信息:(依次为:姓名,学号,成

绩)\\n\

p=(struct student *)malloc(sizeof(struct student)); scanf(\scanf(\scanf(\

printf(\请输入你想要添加到的位置\\n\scanf(\

for(q=head,r=NULL;q!=NULL;r=q,q=q->next) {

if(j==1) {

p->next=head; head=p; break; }

if(k==j) {

p->next=q; r->next=p; break;

优秀学习资料 欢迎下载

} k++; }

if(q==NULL&&j==k) {

q=p;

p->next=NULL; }

if(q==NULL&&j>k)

printf(\你的添加的位置不合法\\n\

return head; }

void prin(struct student *head) {

struct student *p;

for(p=head;p!=NULL;p=p->next) {

printf(\ printf(\ printf(\ printf(\ } }

main() {

struct student *head; head=fun();

head=wall(head); head=park(head); prin(head); }

实验九 文件操作 实验 ( 验证性 综合性 实验 1学时)

优秀学习资料 欢迎下载

1、目的要求:

(1)掌握文件的打开和关闭。 (2)精通文件的读写操作。

(3)了解文件的定位操作及文件的检测函数。 (4)掌握文件的应用。 (5)编写实验报告。

2、实验内容(参考实验指导书): (1)编写一个程序,读取磁盘上的一个C语言程序文件,要求加上注释后再存放到磁盘上,文件可以另外命名。

#include #include void main() {

int i=0,j;

char c,a[80]={\ FILE *p;

if((p=fopen(\ fscanf(p,\

fclose(p);

if((p=fopen(\ {

printf(\ exit(1); }

fputs(\ fprintf(p,a); fputs(\ fclose(p); }

(2)编写一个程序,将文件old.txt从第10行起存放到new.txt中。

#include #include void main() {

int i=0; char c;

FILE *p1,*p2;