Tsukinai的第五十八个程序
请按给定的程序框架,将is_within()函数补充完整。is_within()函数有两个参数,一个是字符,另一个是字符指针。
其功能是如果字符在字符串中,返回值为1;如果字符不在字符串中,返回值为0。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int is_within(char *p, char s);
int main()
{
char a[80], s;
int flag;
gets(a);
s = getchar();
flag = is_within(a, s);
if (flag)
printf("Read the characters in a string.");
else
printf("Read the characters not in the string.");
system("pause");
return 0;
}
int is_within(char *p, char s)
{
int len, i;
len = strlen(p);
for (i = 0; i < len; i++)
{
if (*(p + i) == s)
{
return 1;
}
}
return 0;
}