Lab 4

Store all of your files for this lab in a folder named "lab4".

Information for exercises 2 and 3

A cstring stores the same content as a string, but inside a character array. The number of elements in a character array may exceed the length of the string content that it holds.

For example, a variable like char str[256] may exist but it only contains the string content "hello"; the rest of the character elements being currently unused.

To distinguish the end of string content or string data within a character array, the last character of the string data should always be '\0'.

Thus: str[0] will be 'h', str[1] will be 'e', str[2] will be 'l', str[3] will be 'l', str[4] will be 'o', and str[5] will be '\0'.

Exercise 1

Create a program that outputs only the last 10 lines of it's input. Your solution must use an array. Name your program: tail and your source file: tail.cpp.

Exercise 2

Create a program first by including the following code for your main function: int main() { char cs[128] = "The quick brown fox"; cout << cstr_len(cs) << endl; return 0; }

Implement the function int cstr_len(const char cstr[]); so that the main function will work. cstr_len should return the length of the string content within it's character array parameter.

The program should output: 19

Name your program: testlen and your source file: testlen.cpp

Exercise 3

Create a program first by including the following code for your main function:

int main() { char cs[128] = "The quick brown "; cstr_append(cs, "fox"); cout << cs << endl; return 0; }

Implement the function void cstr_append(char a[], const char b[]); so that the main function will work. cstr_append should append the string content from parameter b into the string content in parameter a.

The program should output: The quick brown fox

Name your program: testapp and your source file: testapp.cpp