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

}

相关推荐
2401_827364561 小时前
迷宫【BFS+结构体\pair】
算法·宽度优先
拓端研究室TRL1 小时前
R软件线性模型与lmer混合效应模型对生态学龙类智力测试数据层级结构应用
开发语言·r语言
于慨2 小时前
计算机考研C语言
c语言·开发语言·数据结构
GGGGGGGGGGGGGG.2 小时前
使用dockerfile创建镜像
java·开发语言
请为小H留灯2 小时前
Python中很常用的100个函数整理
开发语言·python
Bruce Jue2 小时前
算法刷题--贪心算法
算法·贪心算法
达斯维达的大眼睛3 小时前
QT小项目-简单的记事本
开发语言·qt
轩宇^_^3 小时前
C++ 类与对象的实际应用案例详解
开发语言·c++
oioihoii3 小时前
从零到多页复用:我的WPF MVVM国际化实践
开发语言·c#·wpf
c7_ln3 小时前
编程视界:C++命名空间
开发语言·c++·笔记