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

}

相关推荐
x***J34832 分钟前
Python多线程爬虫
开发语言·爬虫·python
m***D28639 分钟前
Python网络爬虫实战案例
开发语言·爬虫·python
甄心爱学习43 分钟前
数据挖掘-聚类方法
人工智能·算法·机器学习
保持低旋律节奏1 小时前
C++——C++11特性
开发语言·c++·windows
ID_180079054731 小时前
基于 Python 的淘宝商品详情数据结构化解析:SKU、价格与库存字段提取
开发语言·数据结构·python
星释1 小时前
Rust 练习册 82:Hamming与字符串处理
开发语言·算法·rust
时间不说谎1 小时前
c/c++的语法糖
开发语言
Laughtin1 小时前
终端Python环境的选择与切换
开发语言·python
头发还在的女程序员2 小时前
基于JAVA语言的短剧小程序-抖音短剧小程序
java·开发语言·小程序
JHC0000002 小时前
Python PDF 相关操作
开发语言·python·pdf