amermo

uneseni znak koji se ponavlja >= 2x zamjeni nekim znakom

Feb 19th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7.  
  8. void zamjeni(char* string, char stari, char novi)
  9. {
  10.     char temp[100];
  11.     char* p = string;
  12.     char* q = temp;
  13.     int counter;
  14.     while(*p != '\0')
  15.     {
  16.         if(*p == stari)
  17.         {
  18.             counter = 0;
  19.             while(*p == stari && *p != '\0')
  20.             {
  21.                 counter++;
  22.                 p++;
  23.             }
  24.             if(counter >= 2)
  25.                 *q++=novi;
  26.         }
  27.         *q++=*p++;
  28.     }
  29.     *q = '\0';
  30.     strcpy(string, temp);
  31. }
  32.  
  33. int main()
  34. {
  35.     char string[] = "XYZZDZZZAW";
  36.     zamjeni(string, 'Z', '*');
  37.     puts(string);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment