两个任务
·编程替代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;
}
}