Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char* strDelIdx(char* str, int idx)
- {
- char* start{ str };
- str += idx;
- while (*str)
- {
- *str = *(str + 1);
- ++str;
- }
- return start;
- }
- char* strDelCh(char* str, const char symbol)
- {
- char* start{ str };
- char* ins{ str };
- while (*ins != symbol and *ins++);
- if (!*ins) { return start; };
- str = ins;
- while (*str++)
- {
- if (*str != symbol)
- {
- *ins++ = *str;
- }
- }
- return start;
- }
- char* strInsCh(char* str, const char symbol, int idx)
- {
- char* start{ str };
- int len{ 0 };
- --idx;
- while (*str++) ++len;
- while (len != idx)
- {
- *str = *(str - 1);
- --str;
- --len;
- }
- *str = symbol;
- return start;
- }
- char* strInsChAlt(char* str, const char symbol, int idx)
- {
- char* start{ str };
- str += idx;
- char copyFirst{ *str };
- *str = symbol;
- char copySecond;
- while (*str++)
- {
- copySecond = *str;
- *str = copyFirst;
- copyFirst = copySecond;
- }
- return start;
- }
- int main()
- {
- char str[50]{ "Hello, bright world!" };
- std::cout << str << '\n';
- std::cout << strDelIdx(str, 5) << '\n';
- std::cout << strDelCh(str, 'l') << '\n';
- //std::cout << strInsChAlt(str, '#', 15) << '\n';
- std::cout << strInsChAlt(str,'l',14) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement