void *memchr(const void *s, int c, size_t n);
#include <stdio.h>
#include <string.h>
int ch = 'w';
char string[] = "hello world";
int main()
{
char *pdest;
int result;
printf ("string to be searched:\n\t\t%s\n", string);
pdest = memchr (string, ch, sizeof(string));
if (pdest != NULL) {
result = pdest - string + 1;
printf ("Result:\t\t%c found at position %d\n", ch, result);
}else
printf ("Result\t\t%c not found\n");
return 0;
}
$ ./memchar
string to be searched:
hello world
Result: w found at position 7
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |