Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. int s = 0, i, counter = 1;
  8. char c, *chars;
  9.  
  10. if(strcmp(argv[1], "e") == 0)
  11. {
  12. c = getchar();
  13.  
  14. if(c != '\n')
  15. {
  16. s++;
  17.  
  18. chars = (char *)malloc(s * sizeof(char));
  19. chars[s-1] = c;
  20. } else
  21. {
  22. printf("\n");
  23. return 0;
  24. }
  25.  
  26. c = getchar();
  27.  
  28. while(c != '\n')
  29. {
  30. s++;
  31. chars = (char *)realloc(chars, s * sizeof(char));
  32.  
  33. chars[s-1] = c;
  34. c = getchar();
  35. }
  36.  
  37. chars[s] = '\0';
  38.  
  39. for(i = 0; i < s; i++)
  40. {
  41. if(chars[i] == chars[i+1] && i < s-1)
  42. {
  43. counter++;
  44. } else
  45. {
  46. printf("%d%c", counter, chars[i]);
  47. counter = 1;
  48. }
  49. }
  50. } else if(strcmp(argv[1], "d") == 0)
  51. {
  52.  
  53. }
  54.  
  55. printf("\n");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement