Jimmy小站
小明也有大梦想 — 蒋明/铭7.3.2 编程题《在字符串中查找某字符》
2015-08-30 / C语言基础题 / 4753 次围观 / 0 次吐槽问题描述】
输入一个字符,再输入一个以回车结束的字符串(少于80 个字符),在字符串中查找该字符。如果找到,则输出该字符在字符串中所对应的最大下标(下标从0开始);否则输出“NotFound”。
【输入形式】
输入一个字符和一个以回车结束的字符串
【输入输出样例1】(下划线部分表示输入)
Input a character: m
Input a string: programming
index=7
【输入输出样例2】(下划线部分表示输入)
Input a character: a
Input a string: 1234
Not Found
#include<stdio.h> #include<string.h> int main(void) { char ch,s[80]; int i=0,index=-1; printf("Input a character: "); scanf("%c",&ch); printf("Input a string: "); scanf("%s",s); while(s[i]!='\0'){ if(s[i]==ch) index=i; i++; } if(index==-1) printf("Not Found"); else printf("index=%d",index); return 0; }
推荐您阅读更多有关于“”的文章
本月热文
Copyright © Jimmy小站 Allrights Reserved.备案号:桂ICP备 15005996
额 本文暂时没人评论 来添加一个吧
发表评论