zoukankan      html  css  js  c++  java
  • 项目开发中的字符串模型

    int main11()//用for实现
    {
    	char *a="wqwqdadadadqeadafdsfewqew";
    	char *b="wq";
    	int i;
    	int icount=0;
    	//	a=strstr(a,"wq");
    	for(;*a!='';)
    	{
    
    		//if(strstr(a,"wq")!=NULL)//这句不对的原因就是strstr自动查找的
    		a=strstr(a,"wq");//按这里来说strstr是自己自动查找的 这里如果不匹配返回NULL
    		if(a!=NULL)
    		{
    			icount++;
    			a=a+strlen("wq");
    		}
    		else//没有这个break还会致错!
    			break;
    
    	}
    	printf("%d 
    ",icount);
    	system("pause");
    }
    

      

    int main22()//用while实现
    {
    	char *a="wqwqdadadadqeadafdsfewqew";
    	char *b="wq";
    	int i;
    	int icount=0;
    	a=strstr(a,"wq");
    	while(a!='')
    	{
    
    		a=strstr(a,"wq");
    		if(a!=NULL)
    		{
    			icount++;
    			a=a+strlen("wq");
    		}
    		else//没有这个break还会致错!
    			break;
    	}
    	printf("%d 
    ",icount);
    	a="wqwqdadadadqeadafdsfewqew";
    	icount=0;
    	while (a=strstr(a,b))//整个循环中直到a中不会再出现b的序列,则返回NULL
    	{
    		icount++;
    		a=a+strlen(b);
    		/*if(*a =='') 因此这步就是多余的
    			break;*/
    	}
    
    	printf("%d 
    ",icount);
    	system("pause");
    }
    

      

    int main33()//用 do while实现
    {
    	char *a="wqwqdadadadqeadafdsfewqew";
    	char *b="wq";
    	int i;
    	int icount=0;
    	
    	do
    	{
    		icount++;
    		a=a+strlen(b);
    	}while(a=strstr(a,"wq"));
    
    	printf("%d 
    ",icount);
    	system("pause");
    }
    

      

    //实现接口
    int showT(char **mya,char ** myb)
    {
    	char **Tmya=mya;
    	char **Tmyb=myb;
    	int icount=0;
    	while( *(Tmya)=strstr(*Tmya,*Tmyb) )
    	{
    		icount++;
    		*Tmya=*Tmya+strlen(*Tmyb);
    	}
    	return icount;
    }
    int main()
    {
    	char *a="wqwqdadadadqeadafdsfewqew";
    	char *b="wq";
    	int i=0;
    	i=showT(&a,&b);
    	printf("%d
    ",i);
    	system("pause");
    }
    

      

    int shouT2(char *mya,char *myb,int *myicount)
    {
    	char *Tmya=mya;
    	char *Tmyb=myb;
    	int *Tmyicount=myicount;
    	*myicount=0;
    	while( Tmya=strstr(Tmya,Tmyb) )
    	{
    		(*myicount)++;//这里导致错误,因为++ 和* 的优先级不同,++的优先级比*的高
    		Tmya=Tmya+strlen(Tmyb);
    	}
    	return *myicount;
    }
    
    int main()
    {
    	char *a="wqwqdadadadqeadafdsfewqew";
    	//char b[]="wq";这里的b出来的是乱码,因为没有字符终止符
    	char *b="wq";
    	int i=0;
    	i=shouT2(a,b,&i);
    	printf("%d
    ",i);
    	system("pause");
    }
    

      

  • 相关阅读:
    零售数据框架
    API安全Checklist
    高级区块链工程师评定
    软件项目复杂性
    e-Commerce电商参考云架构
    面试中的学习能力判断
    SpringCloud微服务架构案例-共享服务中心
    Software Architecture and High Level Design软件架构与概要设计
    基于Istio的ServiceMesh
    a store with that domain name already exists怎么解决
  • 原文地址:https://www.cnblogs.com/xiaochige/p/6654914.html
Copyright © 2011-2022 走看看