Hi there,

Could someone tell me why this aint working? I understand this could be done using strstr() function. I just gave it a try and I cant quite figure out why this piece of code
returns NULL though the search string is present in the main string.

Please let me know.

#include <stdio.h>

char * strpos(char *, char *);

int main()
    char s[] = "I love my job";
    char t[] = "job";
    char *pos = strpos(s, t);

    printf("%s", pos);

    return 0;

char * strpos(char *a, char *b)
    char *pa;
    char *pb;

    for(; *a; a++ )
       for(pa = a, pb = b; *pb && (*pa == *pb); pa++, pb++ )
           if(*pb == '\0')
               return a;
    return NULL;


Last edited by shabbir; 31May2009 at 07:07.. Reason: Code blocks