1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
int main()
{
char a_string[80];
char choices;
char dest[80];
int search (char sourceString [], char targetString [] );
cout << "Enter A String:\n";
cin.getline(a_string,80);
cout << " " << endl;
cout << "Current String: " << a_string << endl;
cout << " " << endl;
const int search_choice = 's', insert_choice = 'i', append_choice = 'a', delete_choice = 'd', replace_choice = 'r', exit_choice = 'e';
cout << " " << endl;
cout << "s-search" << endl;
cout << "i-insert" << endl;
cout << "a-append" << endl;
cout << "d-delete" << endl;
cout << "r-replace" << endl;
cout << "e-exit" << endl;
cout << " " << endl;
cout << "Choose An Option: " << endl;
cin >> choices;
switch (choices)
{
case search_choice:
cout << "Enter a word you want to search: ";
cin >> a_string;
char * p;
p = strchr (a_string, 'x');
if (p==NULL)
cout << "not found";
else
cout << "found" << endl;
// cout << "You Choose: Search";
break;
case insert_choice:
cout << "Enter a string you want to insert: ";
cin >> a_string;
strncpy (dest, a_string,3);
dest[3] = '\0';
strcat (dest, a_string);
strcat (dest, &a_string[2]);
cout << dest << endl;
break;
case append_choice:
cout << "Enter a string you want to append: ";
cin >> a_string;
break;
case delete_choice:
cout << "Enter a string you want to delete: ";
cin >> a_string;
strncpy (dest, a_string,2);
dest[2] = '\0';
strcat (dest, &a_string[8]);
cout << dest << endl;
break;
case replace_choice:
cout << "Enter a string you want to replace: ";
cin >> a_string;
strncpy(dest, a_string,3);
dest[3] = '\0';
strcat (dest, a_string);
strcat (dest, &a_string[7]);
cout << dest << endl;
break;
case exit_choice:
cout << "You Choose: Exit";
break;
default: cout << "Please Enter A Valid Letter ";
break;
}
return 0;
}
| |