[ create a new paste ] login | about

Link: http://codepad.org/Zzut01SR    [ raw code | output | fork ]

C, pasted on Sep 14:
#include <stdio.h>
int main() {
    int len = 25;
    char pat[] = "connection_receive_worker";
    char arr[] = "/usr/lib/smbsrv/smb3d'connection_receive_worker";
    //size_t strl = 
    printf("value %d\n",(unsigned)strlen(arr));
    int i = 0;
    int j = 0;
    for ( i=0;i<(strlen(arr)+strlen(pat));i++) {
        for (j=0;j<strlen(pat)&&(i+j)<strlen(arr);j++){
            if ( pat[j] != arr[i+j] ) {
                break;
            }
            printf("j=%d\n",j);
            if ( j+1 == strlen(pat)) {
                printf("pattern found\n");
            }
        }
    }
                
    return 0;
}


Output:
value 47
j=0
j=1
j=2
j=3
j=4
j=5
j=6
j=7
j=8
j=9
j=10
j=11
j=12
j=13
j=14
j=15
j=16
j=17
j=18
j=19
j=20
j=21
j=22
j=23
j=24
pattern found
j=0
j=0


Create a new paste based on this one


Comments: