C++strchrは文字列を切り取り,プロトコル解析で文字を判断するのに有用である.
852 ワード
#include
const char * strchr ( const char * str, int character );
char * strchr ( char * str, int character );
const char * strchr ( const char * str, int character );
char * strchr ( char * str, int character );
/* strchr example */
#include <stdio.h>
#include <string>
int main ()
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...
",str);
pch=strchr(str,'s');
while (pch!=NULL)
{
printf ("found at %d
",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}
/*
Looking for the 's' character in "This is a sample string"...
found at 4
found at 7
found at 11
found at 18
*/