Advertisement
SergeyPGUTI

8.1.12

Feb 14th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. void deleteChar(char a[], char c)
  9. {
  10.     int length=strlen(a);
  11.     for (int i=0;i<length;i++)
  12.     {
  13.         if (a[i]==c)
  14.         {
  15.             for( int j=i;j<length-1;j++) //смещаем символы правее i-ого влево
  16.             {
  17.                 a[j]=a[j+1];
  18.             }
  19.             length--;// так как произошло смещение ,длина уменьшилась
  20.             i--;// из за смещения i-ый индекс нужно пройти еще раз
  21.         }
  22.     }
  23.     a[length]=0;
  24. }
  25.  
  26. int main()
  27. {
  28.     char str[100]="Hello my name is Ilia, i live in England, i drink lipton;";
  29.     deleteChar(str,'l');
  30.     cout<<str;
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement