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);

}

相关推荐
SilentSamsara2 分钟前
Python 内存管理:引用计数、循环垃圾回收与内存泄漏排查
开发语言·vscode·python·青少年编程·pycharm
广州灵眸科技有限公司6 分钟前
瑞芯微(EASY EAI)RV1126B AI算法开发流程
人工智能·算法·机器学习
Rabitebla1 小时前
【C++】string 类:原理、踩坑与对象语义
linux·c语言·数据结构·c++·算法·github·学习方法
小雅痞2 小时前
[Java][Leetcode middle] 167. 两数之和 II - 输入有序数组
java·算法·leetcode
傻啦嘿哟2 小时前
如何在 Python 中使用 colorama 库来给输出添加颜色
开发语言·python
CN-Dust2 小时前
【C++】输入cin例题专题
java·c++·算法
数模竞赛Paid answer3 小时前
2025年MathorCup数学建模A题汽车风阻预测解题文档与程序
算法·数学建模·mathorcup
geovindu3 小时前
go: Visitor Pattern
开发语言·设计模式·golang·访问者模式
宣宣猪的小花园.3 小时前
C语言重难点全解析:内存管理到位运算
c语言·开发语言·单片机
方安乐7 小时前
python之向量、向量和、向量点积
开发语言·python·numpy