Advertisement
extrica

Untitled

Feb 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. char *izbaci_viska_razmake(char *s) {
  4.  
  5. char *pom = s;
  6. char *pom2;
  7.  
  8. // Izbacivanje s pocetka rijeci
  9. if(*s == ' ') {
  10.  
  11. char *pom1 = s;
  12.  
  13. while(*pom1 == ' ') {
  14.  
  15. pom1++;
  16. }
  17.  
  18. pom2 = pom1;
  19.  
  20. while(*pom2 != '\0') {
  21.  
  22. *s = *pom2;
  23. s++;
  24. pom2++;
  25. }
  26.  
  27. *s = '\0';
  28. }
  29.  
  30. // Izbacivanje visestrukih razmaka
  31. s = pom;
  32. char *pom3, *pom4, *pom5;
  33.  
  34. while(*s != '\0') {
  35.  
  36. if(*s == ' ' && *(s + 1) == ' ') {
  37.  
  38. pom3 = s;
  39. pom5 = s;
  40.  
  41. while(*pom3 == ' ') {
  42.  
  43. pom3++;
  44. }
  45.  
  46. pom4 = pom3;
  47. pom5 = pom5 + 1;
  48.  
  49. while(*pom4 != '\0') {
  50.  
  51. *pom5= *pom4;
  52. pom5++;
  53. pom4++;
  54. }
  55. *pom5 = '\0';
  56. }
  57.  
  58. s++;
  59. }
  60.  
  61. // Izbacivanje razmaka na kraju
  62.  
  63. s = pom;
  64. char *pom6;
  65.  
  66. while(*s != '\0') {
  67.  
  68. s++;
  69. }
  70.  
  71. if(*(s-1) == ' ') {
  72.  
  73. pom6 = s;
  74. pom6 -= 1;
  75.  
  76. while(*pom6 == ' ') {
  77.  
  78. pom6--;
  79. }
  80.  
  81. *(pom6 + 1) = '\0';
  82. }
  83.  
  84. return pom;
  85. }
  86.  
  87. int main() {
  88.  
  89. char s[] = " Volim OR ";
  90.  
  91. printf("%s", izbaci_viska_razmake(s));
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement