c语言 实验八 综合实验报告,实验八实验报告卓越14彭佳伟.doc

实验八实验报告卓越14彭佳伟

C语言程序设计 实验报告

专业 计算机科学与技术 班级 卓越工程师班

日期 2014年12月17日 成绩

第八次实验 指针实验 指导教师 李开

学生姓名 彭佳伟 学 号 U201414716

实验组别 同组人姓名

实验名称 指针实验

一、实验目的

熟练掌握指针的说明、赋值、使用。

掌握用指针引用数组的元素,熟悉指向数组的指针的使用。

熟练掌握字符数组与字符串的使用,掌握指针数组及字符指针数组的用法。

掌握指针函数与函数指针的用法。

掌握带有参数的main函数的用法。

二、实验任务

源程序改错

下面的源程序中是否存在错误?如果存在,原因是什么?如果存在错误,要求在计算机上对这个源程序进行调试修改,使之能够正确执行。

源程序1

#include

int main(void)

{

float *p;

scanf("%f", p);

printf("%f\n", *p);

return 0;

}

源程序完善、修改、替换

下面的源程序的功能是:通过函数指针和菜单选择来调用字符串拷贝函数或字符串连接函数。请在程序中的下划线处填写合适的表达式、语句或代码片段来完善该程序。

#include

#include

int main(void)

{

char a[80], b[80], c[160], *result = c;

int choice, i;

do

{

printf("\t\t1 copy string.\n");

printf("\t\t2 connect string.\n");

printf("\t\t3 exit. \n");

printf("\t\tinput a number(1-3) please! \n");

scanf ("%d", &choice);

}while(choice < 1|| choice > 5);

switch(choice)

{

case 1: p = strcpy; break;

case 2: p = strcat; break;

case 3: goto dowm;

}

getchar();

printf("input the first string please! \n");

i = 0;

printf("input the second string please! \n");

i = 0;

result = (a, b);

printf("the result is %s\n", result);

dowm:

;

return 0;

}

请上机运行第(1)题程序,使之能按下面要求输出结果:

1 copy string.

2 connet string.

3 exit

input a number(1-2) please!

2(输入)

Input the first string please!

the more you learn,(输入)

input the second string please!

the more you get.(输入)

the result is the more you learn, the more you get.

跟踪调试源程序

请按下面的要求对所给的源程序进行操作,并回答问题和排除错误。

单步执行源程序。进入strcpy时,watches窗口中s为何值?返回main时,watches窗口中s为何值?

排除源程序中的错误,使程序输出结果为:there is a bote on the lake.

源程序3

#include

char *strcpy(char *, char*);

int main(void

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值