编写一个函数is_witlun()。它接受两个参数,一个是字符,另一个是字符串指针。其功能是如果字符在字符串中,就返回一个非O值(真);如果字符不在字符串中,就返回O值(假)。在一个使用循环语句为这个函数提供输入的完整程序中进行测试。
#include <stdio.h> int is_within(char *p, char ch); int main(void) { char str[81]; char ch; do { puts("input range string:"); gets(str); puts("input match char:"); ch = getchar(); getchar(); if ( is_within(str, ch) ) puts("Find!"); else puts("Can't find!"); puts("input any char except q to go on."); ch = getchar(); getchar(); } while(ch != 'q'); puts("Quit."); return 0; } int is_within(char *p, char ch) { while(*p != '\0') { if(*p == ch) return 1; p++; } return 0; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题