COP+1000+Daily+Notes+-+Part+3

= //Weeks 9 - 12// =

Week 9
The stringLength program, while simple, demonstrates how to pass an array to a function and of course returning a value for the length of the string passed in. When you create the strcpy and strcat functions, you actually DON'T need to return any values. The target array has already been changed in memory. strCat demonstates how to move through two different strings and move characters from the beginning of one string to the end of another string, in effect apprending one string to the end of the other. This program presents a great opportunity to use the debugger to carefully watch what happens with the variables and the arrays.

//Arrays//
Here is an interesting concept in C++ code format="cpp" cin.ignore; //Adding cin.ignore to the next line clears/ignores the newline from the stream. //For example:

for (i=0; i<10; i++) //array initialized for user input//

//{//

//cout <<"Enter integer #" << i+1 << ": ";// use enters arrayinput

cin >> array[i];

cin.ignore; //clears/ignores newline character in the stream//

//cout << endl;// to add a new line code This would be useful for entering integers into an array.



The StringFind program below demonstrates how to find a substring,, e.g., at in a larger string, e.g., catalog. The function returns either the index of the start of the substring if found, if not found, the function returns a -1. The value of -1 was chosen since it can never be an array index value. Please note, you should test this program thoroughly because it contains a bug. Sample substrings to look for might include, in this order: c - just find the first character ca - find the first set of characters l - find a single character in the string alo - find a set of characters in the string cal - look for a substring that doesn't exist



When you find the error, it is relatively easy to fix. This program is a great time to use the debugger so you can watch the index values increment. You might also add a couple of variable to display the current characters, etc.
 * Debugger Use**