C++ 两个任务:程序替代strcat()函数 在字符串中查找指定的第一个字母位置

两个任务
·编程替代strcat()函数
·在字符串中查找指定的第一个字母位置

#include<iostream>
#include<string>
using namespace std;
void main()
{
	int a,i,l,m,n;
	char ch;
	cout<<"in this system, you have two choices to feel the magic of c++:"<<endl;
	cout<<"1,we can use this procedure to replace of strcat()"<<endl;
	cout<<"2,to find the position of a letter in a character"<<endl;
	cout<<"other number,quit"<<endl;
while(1)
{
	cout<<"press your choice(1, 2 or other number)"<<endl;
	cin>>a;
    ch=getchar();
	if(a==1)
	{
		char stra[15]={0};
		char *a=stra;
		char strb[15]={0};
		char *b=strb;
	    cout<<"please input stra: ";
	    gets(stra);
	    cout<<"please input strb: ";
	    gets(strb);
		m=strlen(strb);
		n=strlen(stra);
		for(i=0;i<m;i++)
		{
			ra[n+1+i]=b[i];
			a[n]=' ';
		}
	    cout<<a<<endl;
	}
	else if(a==2)
	{
		char strc[10];
	    char x,*p;
		p=strc;
		cout<<"please input a retrieved character :"<<endl;
        cin>>strc;
		l=strlen(strc);
		cout<<"\""<<*p<<"\" length is: "<<l<<endl;
		cout<<"please input a letter :"<<endl;
		cin>>x;
		for(i=0;p[i]!='\0';i++)
		{
			if(p[i]==x) break;
		}
		if(i<l)
			cout<<"the first position of the letter is :"<<i+1<<endl;
		else
		    cout<<"no position in"<<strc<<endl;
	}
    else
		break;

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值