void
*memchr(const void *destString, char c, size_t n);
在從destString開始搜尋n個位元組內尋找c第一次出現的位址並返回,若未找到則返回NULL
- /*This file use to record string.h library use */
- #include <string.h>
- #include <stdio.h>
- char HelloBuf[6]="Hello\n";//show chars
- int main()
- {
- char findChar = 'A';
- int AddrNum = memchr(HelloBuf,findChar,6);//取得第一個'l'的位址,memchr(儲存空間,指定字元,搜索長度)
- int postion = AddrNum-(int)(&HelloBuf);
- printf("HelloBuf:%s\n",HelloBuf);
- printf("findChar:%c\n",findChar);
- printf("HelloBuf:%p\n",&HelloBuf);//印出HelloBuf的位址
- printf("AddrNum:%p\n",memchr(HelloBuf,findChar,6));//印出'l'在HelloBuf中的位址
- printf("postion:%d\n",postion);//印出'l'所在HelloBuf中第幾個
- return 0;
- }
有找到字元"l"的結果
將findChar改為’ A ‘進行測試的結果,可以發現AddrNum為0
沒有留言:
發佈留言