玩玩指针

//字符串连接函数
#include<iostream>
using namespace std;
int main()
{
	char*strcat1(char str1[],char str2[]);
	char str1[30]={"liu"},str2[30]={"tao"};
	strcat1(str1,str2);
	cout<<str1<<endl;
	return 0;
}
char*strcat1(char str1[],char str2[])
{
    char*p1,*p2;
    p1=str1;
	p2=str2;
	for(int i=0;i<30;i++,p1++)
		if(*p1=='\0')
		{
		   *p1=*p2;
		   p2++;
		}
     *p1='\0';
	 return p1;
}
//字符串复制函数
#include<iostream>
using namespace std;
int main()
{
	char*strcopy(char str1[],char str2[]);
	char str1[30]={"liu"},str2[30]={"tao"};
	strcopy(str1,str2);
	cout<<str1<<endl;
	return 0;
}
char*strcopy(char str1[],char str2[])
{
    char*p1,*p2;
    p1=str1;
	p2=str2;
	for(int i=0;i<30;i++,p2++)
		if(*p2!='\0')
		{
		   *p1=*p2;
		   p1++;}
     *p1='\0';
	 return p1;
}


//字符串长度计算
#include<iostream>
using namespace std;
int main()
{
	int strlen(char str1[]),s;
	char str1[30]={"liutaofds"};
s=strlen(str1);
	cout<<s<<endl;
	return 0;
}
int  strlen(char str1[])
{
    char*p1;
    p1=str1;
	int j=0;
	for(int i=0;i<30;i++,p1++)
		if(*p1!='\0')
		{
		   j++;}
	 return j;
}

//字符串比较函数
#include<iostream>
using namespace std;
int main()
{
	int  strcat1(char str1[],char str2[]),s;
	char str1[30]={"liu"},str2[30]={"tao"};
	s=strcat1(str1,str2);
   switch(s)
  {
   case 0:cout<<"str1=str2"<<endl;break;
   case 1:cout<<"str1>str2"<<endl;break;
   case -1:cout<<"str1<str2"<<endl;break;
}
	cout<<s<<endl;
	return 0;
}
int strcat1(char str1[],char str2[])
{
    char*p1,*p2;
    p1=str1;
	p2=str2;
	for(int i=0;i<30;i++,p1++,p2++)
	{if(*p1>*p2)
		{
	 return 1;
		}
     	if(*p1<*p2)
		{
		    return -1;
		}
	}
return 0;
}

你可能感兴趣的:(ios,ios,ios,C++,C++,struct,struct,iostream)