Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- char* copystr(char*);
- char* phone_number(char*);
- void char_change(char*, char, char);
- bool pali_text(char*);
- void delete_char(char*&, char);
- int main()
- {
- cout << "First exercise\n";
- //First exercise
- char s[] = "+38(099)714-55-12";
- cout << phone_number(s) << endl;
- cout << "Second exercise\n";
- //Second exercise
- char a[] = "fsdfsd fsdfsd fsdfewrf fsdfsdf";
- cout << a << endl;
- cout << endl;
- char_change(a, ' ', 9);
- cout << a << endl;
- cout << endl;
- cout << "Third exercise\n";
- //third exercise
- char b[] = "ababa";
- cout << pali_text(b) << endl;
- cout << "Last exercise \n";
- //last exercise
- char* z = copystr(a);
- delete_char(z, 'f');
- cout << z << endl;
- }
- char* copystr(char* str){
- char* tmp = nullptr;
- tmp = new char[strlen(str)+1];
- for(int i = 0; str[i] != '\0'; i++)
- tmp[i] = str[i];
- tmp[strlen(str)] = '\0';
- return tmp;
- }
- //first exercise
- char* phone_number(char* string)
- {
- char* tmp = new char[20];
- for(int i = 0, j = 0; string[i] != '\0'; i++)
- {
- if(isdigit(string[i]))
- {
- tmp[j] = string[i];
- j++;
- }
- }
- return copystr(tmp);
- }
- //secon exercise
- void char_change(char* string, char in, char out)
- {
- for(int i = 0; string[i] !='\0'; i++)
- if(string[i] == in) string[i] = out;
- }
- //third exercise
- bool pali_text(char* string)
- {
- for(int i = 0, j = strlen(string)-1; i <= strlen(string)/2;i++)
- if(string[i] != string[j-i])
- return false;
- return true;
- }
- //last exercise
- void delete_char(char*& string, char chr)
- {
- char* tmp = new char[100];
- for(int i = 0, j = 0; string[i] != '\0'; i++)
- {
- if(string[i] != chr)
- {
- tmp[j] = string[i];
- j++;
- }
- }
- delete[] string;
- string = copystr(tmp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement