Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define __USE_GNU //memrchr, rawmemchr
- #include <string.h>
- int main (int argc, char **argv){
- char str1[]="https://www.example.org";
- char *retStr;
- int c = '.';
- /*
- scan memory for a character
- void *memchr(const void *str, int c, size_t n)
- void *memrchr(const void *str, int c, size_t n);
- void *rawmemchr(const void *str, int c);
- */
- retStr = memchr(str1, c, strlen(str1));
- if(retStr == NULL) printf("not found (1)");
- else printf("%s\n%s\n",str1,retStr);
- retStr = memrchr(str1, c, strlen(str1));
- if(retStr == NULL) printf("not found (2)");
- else printf("%s\n",retStr);
- //testing
- retStr = rawmemchr(str1, '\0');
- printf("%lu %lu\n",strlen(str1),retStr-str1);
- return 0;
- }
- /*
- https://www.example.org
- .example.org
- .org
- 23 23
- */
Advertisement
Add Comment
Please, Sign In to add comment