C++ 两个任务:程序替代strcat()函数 在字符串中查找指定的第一个字母位置
程序员文章站
2022-06-22 18:02:42
两个任务·编程替代strcat()函数·在字符串中查找指定的第一个字母位置#include#includeusing 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++:"<
两个任务
·编程替代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;
}
}
本文地址:https://blog.csdn.net/halahalahahaha/article/details/109647503
上一篇: 智慧地铁搭建纪实:数字可视化大屏+组态软件,凭啥这么强?
下一篇: 撰写推广软文的方法分析