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

}

相关推荐
Dlrb121121 小时前
C语言-指针三
c语言·算法·指针·const·命令行参数
kkeeper~21 小时前
0基础C语言积跬步之深入理解指针(5下)
c语言·开发语言
Tisfy21 小时前
LeetCode 2540.最小公共值:双指针(O(m+n))
算法·leetcode·题解·双指针
一直不明飞行21 小时前
Java的equals(),hashCode()应该在什么时候重写
java·开发语言·jvm
IronMurphy21 小时前
【算法四十七】152. 乘积最大子数组
算法
盲敲代码的阿豪21 小时前
Python 入门基础教程(爬虫前置版)
开发语言·爬虫·python
basketball6161 天前
C++ 构造函数完全指南:从入门到进阶
java·开发语言·c++
互联科技报1 天前
2026超融合选型:Top5品牌与市场格局解读
开发语言·perl
weixin199701080161 天前
[特殊字符] 智能数据采集:数字化转型的“数据石油勘探队”(附Python实战源码)
开发语言·python
淘矿人1 天前
Claude辅助DevOps实践
java·大数据·运维·人工智能·算法·bug·devops