24、C++在给定的字符串中查找指定的字符

来源:互联网 发布:桌面网络图标不见了 编辑:程序博客网 时间:2024/05/25 18:10

   在给定的字符串中查找指定的字符,如果找到的话,则返回该字符在字符串中的地址,并输出该字符串中从该字符起以后的字符,否则返回空值

#include<iostream>using namespace std;char *Findchar(char *p1, char t){    char *p2;    p2=p1;    while(*p2)    {      if((*p2)==t)      {         return p2;      }      p2++;    }    return NULL;}void main(){   char s[30]="perfect",*p;   char c='e';   p=Findchar(s,c);   if (p==NULL) cout<<"Can not find the char "<<c <<endl;   else cout<<p<<endl;}

结果:


这里写图片描述

0 0
原创粉丝点击