I have a small doubt in the implementation of memchr function implementation in the code shown below.
[insert]In the lineCode:#include <stdio.h> #include <string.h> #include <stdlib.h> void * xmemchr(const void *buffer, int ch, size_t count); int main(int argc, char *argv[]) { char *p; char *s = "This is a test"; //p = memchr(s,'e',14); p = xmemchr(s,'e',14); printf("\n %p \t %s \t %c \n", p, p, *p); return 0; } void * xmemchr(const void *buffer, int ch, size_t count) { int i; char c; char *s = buffer; for(i = 0; i< count ; i++) { if(*s == ch){ return s; } else s++; } }
if(*s == ch)
i was assuming how can i compare the char contained in s and the int value that ch has or is it that the compiler does this check on its own. I mean how is it possible to compare a char and an integer. Though i got it working but this point is yet unclear to me.



LinkBack URL
About LinkBacks


