Advertisement
Guest User

Untitled

a guest
Apr 9th, 2022
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /*C program to remove consecutive repeated characters from string.*/
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.  
  8. char str[100];
  9. int i,j,len,len1;
  10.  
  11. /*read string*/
  12. printf("Enter any string: ");
  13. gets(str);
  14.  
  15. /*calculating length*/
  16. for(len=0; str[len]!='\0'; len++);
  17.  
  18. /*assign 0 to len1 - length of removed characters*/
  19. len1=0;
  20.  
  21. /*Removing consecutive repeated characters from string*/
  22. for(i=0; i<(len-len1);)
  23. {
  24. if(str[i]==str[i+1])
  25. {
  26. /*shift all characters*/
  27. for(j=i;j<(len-len1);j++)
  28. str[j]=str[j+1];
  29. len1++;
  30. }
  31. else
  32. {
  33. i++;
  34. }
  35. }
  36.  
  37. printf("String after removing characaters: %s\n",str);
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement