2009年7月20日 星期一

strstr --- 搜尋字串

strstr --- 找出字串第一次出現的地方
(搜尋字串)

函式:
const char * strstr ( const char * str1, const char * str2 );
char * strstr ( char * str1, const char * str2 );

標頭檔:
string.h

說明:
Locate substring
Returns a pointer to the first occurrence of str2 in str1,
or a null pointer if str2 is not part of str1.
The matching process does not include the terminating null-characters.


example:
#include <stdio.h>
#include <string.h>

int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
puts (pch);
return 0;
}


ref :
Here

沒有留言:

張貼留言