RicardasSim

memchr, memrchr, rawmemchr

May 14th, 2019
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define __USE_GNU //memrchr, rawmemchr
  4. #include <string.h>
  5.  
  6. int main (int argc, char **argv){
  7.  
  8. char str1[]="https://www.example.org";
  9. char *retStr;
  10. int c = '.';
  11.  
  12. /*
  13. scan memory for a character
  14. void *memchr(const void *str, int c, size_t n)
  15. void *memrchr(const void *str, int c, size_t n);
  16. void *rawmemchr(const void *str, int c);
  17. */
  18.  
  19. retStr = memchr(str1, c, strlen(str1));
  20.  
  21. if(retStr == NULL) printf("not found (1)");
  22. else printf("%s\n%s\n",str1,retStr);
  23.  
  24. retStr = memrchr(str1, c, strlen(str1));
  25. if(retStr == NULL) printf("not found (2)");
  26. else printf("%s\n",retStr);
  27.  
  28. //testing
  29. retStr = rawmemchr(str1, '\0');
  30. printf("%lu %lu\n",strlen(str1),retStr-str1);
  31.  
  32.  
  33. return 0;
  34. }
  35.  
  36. /*
  37. https://www.example.org
  38. .example.org
  39. .org
  40. 23 23
  41. */
Advertisement
Add Comment
Please, Sign In to add comment