void *memchr(const void *buf, int c, size_t count);
Parameter:
buf: con trỏ tới vùng dữ liệu
c: kí tự cần tìm kiếm
count: số byte kí tự cần tìm kiếm.
Remark:
Hàm memchr( ) tìm kiếm kí tự c trong giới hạn count byte kí tự.
- Hàm sẽ trả về vị trí đầu tiên mà kí tự c xuất hiện.
- Nếu không tìm thấy, hàm sẽ trả về NULL
Ví dụ:
#include "stdio.h" #include "conio.h" #include "string.h" void main( void ) { char str[] = "vncoding forum"; int c = 'o'; char *des; des = (char*)memchr(str, c, 3); if(des == NULL) printf("\nNot found"); else printf("\n%c occur at %d", c, des - str + 1); des = (char*)memchr(str, c, 10); if(des == NULL) printf("\nNot found"); else printf("\n'%c' occurs at %d", c, des - str + 1); getch(); }
Kết quả:
Leave a Reply
You must be logged in to post a comment.