Advertisement
NickAndNick

Функция удаляет набор символов из Unicode-строки

Dec 27th, 2012
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5.  
  6. #define BUF 256
  7.  
  8. void remove_chars(wchar_t *, wchar_t *);
  9.  
  10. int main() {
  11.     wchar_t buffer[BUF], suite[BUF];
  12.     _wsetlocale(LC_CTYPE, L"Russian_Russia.866");
  13.     wprintf(L"Ввести строку:  ");
  14.     _getws_s(buffer, BUF);
  15.     wprintf(L"Введите символы, которые следует удалить:  ");
  16.     _getws_s(suite, BUF);
  17.     remove_chars(buffer, suite);
  18.     wprintf_s(L"%s\n", buffer);
  19.     _getwch();
  20.     return 0;
  21. }
  22.  
  23. void remove_chars(wchar_t * _string, wchar_t * _suite_chars) {
  24.     size_t next;
  25.     wchar_t * pdest = NULL, * beg, * last = _string + wcsnlen(_string, BUF) - 1;
  26.  
  27.     for (next = 0; _suite_chars[next] != 0; next++) {
  28.         do {
  29.             pdest = wcschr(_string, _suite_chars[next]);
  30.             if (pdest) {
  31.                 beg = pdest;
  32.                 for (++beg; beg <= last; beg++) *(beg - 1) = *beg;
  33.                 *(beg - 1) = 0;
  34.                 --last;
  35.             }
  36.         } while (pdest);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement