c - Finding substring in a string -
i writing function find substring. not sure going wrong. on running gdb segmentation fault. if can guide me in right direction.
here code
char *mystrstr(char * s1, const char * s2) int main(){ char *s1 = "the quick brownish fox jumps on hell lazy dog"; char *s2 = "hello"; char *s4; s4 = mystrstr(s1,s2); printf("%s\n",s4); <--- seg. faulting homecoming 0; }
when s2 not substring of s1 returning null, , trying print it, gives segmentation fault.
try this:
s4 = mystrstr(s1,s2); if(s4 != null) printf("%s\n",s4);
c
No comments:
Post a Comment