amermo

izbaci rijec iz stringa(podstring) - string.h

Feb 15th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. void izbaci(char* string, char* podstring)
  7. {
  8.     int i = 0;
  9.     char* indeks = strstr(string,podstring);
  10.     int duzinaPodstringa=strlen(podstring);
  11.     while ((indeks != NULL) && (*(indeks) != '\0'))
  12.     {
  13.         if ((*(indeks-1) == ' ') && (*(indeks+duzinaPodstringa) == ' ' || *(indeks+duzinaPodstringa) == '\0'))
  14.         {
  15.             while ( *(indeks+i) != '\0')
  16.             {
  17.                 *(indeks+i) = *(indeks+i+duzinaPodstringa);
  18.                 i++;
  19.             }
  20.             *(indeks+i) = *(indeks+i+duzinaPodstringa);
  21.  
  22.         }
  23.  
  24.         i = 0;
  25.         indeks++;
  26.         indeks = strstr(indeks,podstring);
  27.     }
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33.     char string[] = "test ovu izbaci";
  34.     izbaci(string, "ovu");
  35.     puts(string);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment