(c programming) I have those two functions memcmp() and strstr()(they are working), I want to implement memcmp()...
Fantastic news! We've Found the answer you've been seeking!
Question:
(c programming) I have those two functions memcmp() and strstr()(they are working), I want to implement memcmp() inside strstr()without calling it
I tried many times but I always get no result
int memcmp(const void* s1, const void* s2,size_t n){ const unsigned char *p1 = s1, *p2 = s2; while(n--) if( *p1 != *p2 ) return *p1 - *p2; else p1++,p2++; return 0;}char *StrSearch(const char *Haystack, const char *Needle){ size_t n = StrGetLength(pcNeedle); while(*pcHaystack) if(!memcmp(pcHaystack++,pcNeedle,n)) return (char *) Haystack - 1; return 0;}
This was my code after I tried to implement it inside strstr()(doesn't work)
char *strstr(const char *Haystack, const char *Needle){ const unsigned char *p1 = (void *)Haystack++, *p2 = (void *)Needle; size_t n = StrGetLength(Needle); while(*Haystack) {while(n--) { if (*p1 != *p2) { if ((*p1 - *p2)) { return (char *) Haystack - 1;} else {return 0;} } else { (const unsigned char *)Haystack++; (const unsigned char *)Needle++; } } } return 0;}
Related Book For
Foundations of Financial Management
ISBN: 978-1259024979
10th Canadian edition
Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta
Posted Date: