C Primer Plus(第六版)11.13 编程练习 第6题

#include<stdio.h>

#define SIZE 40

int is_within(char ch,char str[]);

int main(void)

{

int i = 0;

char *p;

char ch;

char store[SIZE] = "abcd";

while(ch!='q')

{

printf("q to quit\n");

scanf("%c",&ch);

while (getchar() != '\n')

continue;

i = is_within(ch,store);

if(i!=0)

printf("%c在%s第%d位\n",ch,store,i);

else printf("没找到%c\n",ch);

}

return 0;

}

int is_within(char ch,char str[])

{

char *p=NULL;

int i=0;

while(i<sizeof(str))

{

if(str[i] == ch)

{

p=&str[i];

}

i++;

}

if(p==NULL)

return 0;

else

return (p-str+1);

}

相关推荐
Paxon Zhang5 小时前
数据结构之**二叉树**超全秘籍宝典2
java·数据结构·算法
2501_930707786 小时前
使用C#代码添加或删除PPT页面
开发语言·c#·powerpoint
百锦再6 小时前
金仓数据库提出“三低一平”的迁移理念
开发语言·数据库·后端·python·rust·eclipse·pygame
茉莉玫瑰花茶6 小时前
从零搭建 C++ 在线五子棋对战项目:从环境到上线,全流程保姆级教程
开发语言·c++
卡卡酷卡BUG6 小时前
2025年Java面试题及详细解答(MySQL篇)
java·开发语言·mysql
野生工程师6 小时前
【Python爬虫基础-1】爬虫开发基础
开发语言·爬虫·python
wuwu_q6 小时前
彻底讲清楚 Kotlin 的 when 表达式
android·开发语言·kotlin
北城以北88886 小时前
SSM--MyBatis框架之动态SQL
java·开发语言·数据库·sql·mybatis
木易 士心6 小时前
Android 开发核心技术深度解析
android·开发语言·python
迷途之人不知返6 小时前
链表相关的算法题(2)
数据结构·算法·链表