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

}

相关推荐
浅时光_c19 分钟前
3 shell脚本编程
linux·开发语言·bash
Evand J38 分钟前
【三维轨迹目标定位,CKF+RTS,MATLAB程序】基于CKF与RTS平滑的三维非线性目标跟踪(距离+方位角+俯仰角)
开发语言·matlab·目标跟踪
_深海凉_1 小时前
LeetCode热题100-有效的括号
linux·算法·leetcode
今天又在写代码1 小时前
java-v2
java·开发语言
competes2 小时前
慈善基金投资底层逻辑应用 顶层代码低代码配置平台开发结构方式数据存储模块
java·开发语言·数据库·windows·sql
Ulyanov2 小时前
用Pyglet打造AI数字猎人:从零开始的Python游戏开发与强化学习实践
开发语言·人工智能·python
独自归家的兔3 小时前
OCPP 1.6 协议详解:StatusNotification 状态通知指令
开发语言·数据库·spring boot·物联网
希望永不加班3 小时前
Spring AOP 代理模式:CGLIB 与 JDK 动态代理区别
java·开发语言·后端·spring·代理模式
RNEA ESIO3 小时前
PHP进阶-在Ubuntu上搭建LAMP环境教程
开发语言·ubuntu·php
23471021273 小时前
4.15 学习笔记
开发语言·软件测试·python