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

}

相关推荐
半桶水专家1 天前
go语言中的结构体嵌入详解
开发语言·后端·golang
长安er1 天前
LeetCode215/347/295 堆相关理论与题目
java·数据结构·算法·leetcode·
元亓亓亓1 天前
LeetCode热题100--62. 不同路径--中等
算法·leetcode·职场和发展
在屏幕前出油1 天前
二、Python面向对象编程基础——理解self
开发语言·python
小白菜又菜1 天前
Leetcode 1925. Count Square Sum Triples
算法·leetcode
阿方索1 天前
python文件与数据格式化
开发语言·python
登山人在路上1 天前
Nginx三种会话保持算法对比
算法·哈希算法·散列表
写代码的小球1 天前
C++计算器(学生版)
c++·算法
AI科技星1 天前
张祥前统一场论宇宙大统一方程的求导验证
服务器·人工智能·科技·线性代数·算法·生活
weixin_440730501 天前
java结构语句学习
java·开发语言·学习