系统级编程-lab4 下载本文

内容发布更新时间 : 2024/5/17 20:13:16星期一 下面是文章的全部内容请认真阅读。

Practice 1: ArrayStorage.cpp

①将字符数组a与b的首地址传入Initialize ()方法后,对a中的各个元素进行赋值,将字符数组a的0到8位赋值为字符数组“This is A”。

②又将a的首地址赋值给b的首地址,则在此时,b已经变为指向字符数组a的指针,与a等效。则b[8] = ‘B’就是将“This is A”改为“This is B”,未对字符数组b进行任何操作。 ③所以当Initialize ()方法运行结束后,字符数组a的内容为“This is A”,而字符数组b的内容仍为空。

Practice 2: strchr.cpp

Fgets();

fgets()用来从参数stream 所指的文件内读入字符并存到参数s 所指的内存空间, 直到出现换行字符、读到文件尾或是已读了size-1 个字符为止, 最后会加上NULL 作为字符串结束.

Strchr();

用来查找某字符在字符串中首次出现的位置,其原型为: char * strchr (const char *str, int c);

【参数】str 为要查找的字符串,c 为要查找的字符。

strchr() 将会找出 str 字符串中第一次出现的字符 c 的地址,然后将该地址返回。

Strncmp();

strncmp() 用来比较两个字符串的前n个字符,区分大小写,其原型为:

int strncmp ( const char * str1, const char * str2, size_t n );

【参数】str1, str2 为需要比较的两个字符串,n为要比较的字符的数目。

字符串大小的比较是以ASCII 码表上的顺序来决定,此顺序亦为字符的值。strncmp()首先将s1 第一个字符值减去s2 第一个字符值,若差值为0 则再继续比较下个字符,直到字符结束标志'\\0',若差值不为0,则将差值返回。例如字符串\和\比较则会返回字符\和'b'(98)的差值(-33)。

Practice 3: Decoding Lab: Understanding a Secret Message

Decoding Lab (Part 1)

Objectives:

For this exercise, you have to compile a program as attached and supply four secret keys to determine the contents. In this laboratory, you have to supply the first two. The

remaining will be done next week. I will guide you to solve the problem. This exercise is extracted from the CTE, SSD6 – Exercise one.

The details are as follows.

Start the program:

1) invoke the visual C++ and use new to start the workplace.

2) Select the New Menu and click “workplace”. The name is called exercise 1 3) The project is exercise 1: Select Win32 Console

4) The output after selecting the project is as follows.

5) Select the empty button until you see the following screen