/* FILE: fn-test.cpp * example of an interactive test-driver for a string function * this example shows how to test a string function, del_n * * warning: do not write a test-driver that reads both strings and * ints from the keyboard, as it requires consuming the NEWLINE used * to enter an int from the keyboard. Instead, handcode the int * value used by your program, as shown in this example. */ #include #include // for strlen, strcpy, strchr, etc. void del_n(char str[], int n); const int N = 3; // no. of chars to delete from string s /* main() ------------------------------------------------ */ void main(){ char s[80]; //input string to test del_n //prompt and read s cout << "\nEnter s: "; cin.getline(s, 80); //driver loop while(cin){ cout << endl << "s, len before delete: " << endl << s << endl << strlen(s); del_n(s, N); cout << endl << "s, len after delete: " << endl << s << endl << strlen(s); // prompt and read s cout << "\nEnter s: "; cin.getline(s, 80); } } /* del_n() ------------------------------------------- * deletes first n chars from str * PRE: strlen(str) > 0 */ void del_n(char str[], int n){ strcpy(str, &str[n]); }