NotAlpha102

Refactoring string

Jul 5th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. void RemoveChars(char *s, char c)
  5. {
  6.     int writer = 0, reader = 0;
  7.  
  8.     while (s[reader])
  9.     {
  10.         if (s[reader]!=c)
  11.         {
  12.             s[writer] = s[reader];
  13.             writer++;
  14.         }
  15.  
  16.         reader++;
  17.     }
  18.  
  19.     s[writer]=0;
  20. }
  21. main()
  22. {
  23.  
  24.     int n=6;
  25.     char ch1[n], ch2[n];
  26.     int i, ch2_indx=0;
  27.     for(i=0; i<n; i++)
  28.     {
  29.         scanf("%c", &ch1[i]);
  30.     }
  31.  
  32.  
  33.     for(i=0; i<n; i++)
  34.     {
  35.         if(ch1[i]=='a' || ch1[i]=='e' ||ch1[i]=='i'||ch1[i]=='o'||ch1[i]=='u'||
  36.            ch1[i]=='A' || ch1[i]=='E' ||ch1[i]=='I'||ch1[i]=='O'||ch1[i]=='U')
  37.         {
  38.             ch2[ch2_indx++]=ch1[i];
  39.             RemoveChars(ch1, ch1[i]);
  40.  
  41.         }
  42.         ch2[ch2_indx]='\0';
  43.     }
  44.    
  45.     strcat(ch1,ch2);
  46.  
  47.  for(i=0; i<strlen(ch1); i++)
  48.     printf("%c", ch1[i]);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment