diff options
Diffstat (limited to 'CST116F2021-Lab7/Functions.cpp')
| -rw-r--r-- | CST116F2021-Lab7/Functions.cpp | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/CST116F2021-Lab7/Functions.cpp b/CST116F2021-Lab7/Functions.cpp index de7de7f..cefd0ea 100644 --- a/CST116F2021-Lab7/Functions.cpp +++ b/CST116F2021-Lab7/Functions.cpp @@ -48,9 +48,8 @@ int displayStrings(string data[]) } -//prints out "match found" each time a letter of the user string is found. -//once a match for the first letter is found, then it moves onto the next, printing "match found" for each match -void findString(string data[]) +//findString definition +int findString(string data[]) { //initializations int cntData = 0; @@ -96,7 +95,7 @@ void findString(string data[]) { cout << "\n\"" << user << "\" has been found in the display" << endl; - exit(0); + return 1; } } cntDataChar++; @@ -106,4 +105,53 @@ void findString(string data[]) } cout << "\n\"" << user << "\" has not been found in the display"; +} + +//removeString definition +int removeString(string data[]) +{ + //initializations + int a = 0; + int b = 0; + int c = 0; + + string userDelete; + + //prompt + cout << "\nEnter a string to delete from your display: "; + cin >> userDelete; + + cout << endl; + + //find + while (data[a] != "\0") + { + if (data[a] == userDelete) + { + cout << "\"" << data[a] << "\"" << " has been deleted.\n"; + break; + } + else + { + a++; + } + } + const int removePos = a; + + //remove + while (data[b+1] != "\0") + { + b++; + } + while (c <= (b - removePos)) + { + + data[a] = data[a + 1]; + a++; c++; + } + + //redisplay results + displayStrings(data); + + return 1; }
\ No newline at end of file |