#include <string.h>
char *strchr (const char *s, int c);
#include <stdio.h>
#include <string.h>
int main()
{
const char *s = "hello world";
char *p = NULL;
char c;
printf ("input a char want to find: ");
scanf ("%c", &c);
if (!strchr(s, c)) {
printf ("Not found!\n");
return (1);
}
printf ("%c\n", *strchr(s, c));
return (0);
}
$ ./strchr
input a char want to find: o
o
$ ./strchr
input a char want to find: z
Not found!
char * strchr(const char * s, int c)
{
for(; *s != (char) c; ++s)
if (*s == '\0')
return NULL;
return (char *) s;
}
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |