Advertisement
gewur33

Untitled

Oct 30th, 2014
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. /* struk prog ue08
  2. #4
  3. Suche nach Teilzeichenkette */
  4.  
  5. #include<stdlib.h>
  6. #include<stdio.h>
  7.  
  8. char text[] = "dieses da ist es";
  9. char pattern[] = "es";
  10.  
  11. int countlength(char inputstring[]) {
  12.     char pos = inputstring[0];
  13.     int length = 0;
  14.     while(pos != '\0') {
  15.         ++length;
  16.         pos = inputstring[length];
  17.         }
  18.     return length;
  19. }
  20.  
  21. int main (int argc, char * argv[]) {
  22.     int textlength=countlength(text);
  23.     int ipos = textlength-1;
  24.     int counter = 0;
  25.     while (ipos > 0) {
  26.         if ((text[ipos] == pattern[0]) && (text[ipos+1] == pattern[1])) {
  27.             ++counter; // könnte man ausgeben, wie oft es gematched hat..
  28.             printf("%d \n",ipos);
  29.             --ipos;
  30.         }
  31.         --ipos;
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement