the default standard lib funtions in a naive way, just for the sake of it.
And this is the code of despair. It's horrible, debugged with printfs, but it's the place where I got it :)
https://pastebin.com/LD0JMp64
Only for curious. I don't ask for help that much because I'm just going to rewrite it when my head is fresh, but just for curiosity, wtf?
print unsigned int not int
also put hard casts where ever you can.
do you mean casting (void *) to (unsigned char *)?
what are you trying to do?
a naive implementation of memmem, a function on string.h
P.s. I figured it out , sent the code a few messages above
void* meme(const void* m, size_t msz, const void* s, size_t ssz){ const void* f = m; while( (f=memchr(f, *(char*)s, msz-(f-m)) ){ if( f-m < ssz ) return NULL; if( !memcmp(f,s,ssz) ) return f; ++f; } return NULL; }
Btw what happens when ssz == 1, And the first char is s then?
I mean it seems to be returning NULL for the case When the first chr is the match and ssz == 1
ssz - 1 should be the case
Wait no...
Обсуждают сегодня