Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* struk prog ue08
- #4
- Suche nach Teilzeichenkette */
- #include<stdlib.h>
- #include<stdio.h>
- char text[] = "dieses da ist es";
- char pattern[] = "es";
- int countlength(char inputstring[]) {
- char pos = inputstring[0];
- int length = 0;
- while(pos != '\0') {
- ++length;
- pos = inputstring[length];
- }
- return length;
- }
- int main (int argc, char * argv[]) {
- int textlength=countlength(text);
- int ipos = textlength-1;
- int counter = 0;
- while (ipos > 0) {
- if ((text[ipos] == pattern[0]) && (text[ipos+1] == pattern[1])) {
- ++counter; // könnte man ausgeben, wie oft es gematched hat..
- printf("%d \n",ipos);
- --ipos;
- }
- --ipos;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement