⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 st.cpp

📁 自己做的c库函数
💻 CPP
字号:
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <setjmp.h>
   //  int pos=0;
jmp_buf rek;
	 
	 int num=0;
	inline test(int k)
	{
		if(k!=0)
			return 1;
		else
			longjmp(rek,-1);
	}
	/*
char* strtokx(char *b,const char *dli)
{
static	char *buf=NULL;
	  int pos=0;
//	 char *buf=NULL;
	char *re=NULL;
	if(b==NULL)
	{
		if(buf==NULL)
			return NULL;
		for(;buf[pos]==*dli&&buf[pos+1]!='\0';pos++){}
		re=buf+pos;
		for(;buf[pos]!=*dli&&buf[pos+1]!='\0';pos++){}
		if(buf[pos+1]=='\0')
		{
			buf=NULL;
			return re;

		}
		else
		{
		buf[pos]='\0';
		buf=buf+pos+1;
		}

	}
	else
	{
		buf=b;
		pos=0;
		if(buf==NULL)
			return NULL;
		for(;buf[pos]==*dli&&buf[pos+1]!='\0';pos++){}
		re=buf+pos;
		for(;buf[pos]!=*dli&&buf[pos+1]!='\0';pos++){}
		if(buf[pos]=='\0')
		{
			buf=NULL;
			return re;
		}
		else
		{
		buf[pos]='\0';
		buf=buf+pos+1;
		}

	}
	setjmp(rek);
	return re;
}
*/
	char* strtokx(char *b,const char *dli)
	{
     static	char *buf=NULL;
	  int pos=0;
	char *re=NULL;
	if(b!=NULL)
    {
		buf=b;
		pos=0;
	}
		if(buf==NULL)
			return NULL;
		for(;buf[pos]==*dli&&buf[pos+1]!='\0';pos++){}
		re=buf+pos;
		for(;buf[pos]!=*dli&&buf[pos+1]!='\0';pos++){}
		if(buf[pos+1]=='\0')
		{
			buf=NULL;
			return re;
		}
		else
		{
		buf[pos]='\0';
		buf=buf+pos+1;
		}


	return re;
	}
void main()
{
	char buf[48]="%%%%no.1%%%%%%%no.2%%%%%no.3%no.4";
	char *dli="%";
	char *item=NULL;
	item=strtokx(buf,dli);
	while(item!=NULL)
	{
		cout<<item<<endl;
		item=strtokx(NULL,dli);
	}
}
/*
void main()
{
	int j=0;
	char bu[48]="no.1!!!!!!!!no.2!!!no.3!no.4@@@@@";
	int k=100;
	int v=94;
	char buf[15];
	char x[128]="%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
	//memset(buf,'\0',5);
	printf("j=%d bu=%d %d\n",&j,bu);
	printf("bu=%d buf=%d %d  x=%d %d\n",bu,buf,bu-buf,x,buf-x);
		memcpy(buf,x,50);
		//memcpy(buf,bu,4)//strtok中以'\0'作为最终判断界定符//所以当(任何原因)结尾不为、\0时会越界;;(简单的overflow)
	char *item;
	//bu[2]='^';
	char *dli="!";////////
	cout<<"buf"<<buf<<endl;
	cout<<"bu"<<bu<<endl;
	//sprintf(buf,"%s  %s   %s %s","no.1","no.2","no.3","no.4");
	item=strtok(buf,dli);
	//cout<<item<<endl;
	cout<<"               "<<endl;
	while(item!=NULL)
	{
		 cout<<item<<endl;
       item=strtok(NULL,dli);
	  
	}
	for(int i=0;i<32;i++)
	{
		printf("%d %d    %c %d +++++++ %d %d    %c %d\n",buf+i,i,buf[i],buf[i],bu+i,i,bu[i],bu[i]);
	}

}
///////vc6 lib中strtok 's 弟二个参数为const char *即必须为一个NULLterminate string毫无意义
//取第一个char作为分割符
*/
/*
00401163   jmp         strtokx+11Eh (0040116e)
00401165   mov         ecx,dword ptr [ebp-4]
00401168   add         ecx,1
0040116B   mov         dword ptr [ebp-4],ecx
0040116E   mov         edx,dword ptr [pos (004299b8)]
00401174   add         edx,dword ptr [ebp-4]
00401177   movsx       eax,byte ptr [edx]
0040117A   mov         ecx,dword ptr [ebp+0Ch]
0040117D   movsx       edx,byte ptr [ecx]
00401180   cmp         eax,edx
00401182   je          strtokx+146h (00401196)
00401184   mov         eax,[pos (004299b8)]
00401189   add         eax,dword ptr [ebp-4]
0040118C   movsx       ecx,byte ptr [eax+1]
00401190   test        ecx,ecx
00401192   je          strtokx+146h (00401196)//strtokx+1F7
00401194   jmp         strtokx+115h (00401165)
28:           buf[pos]='\0';
00401196   mov         edx,dword ptr [pos (004299b8)]
0040119C   add         edx,dword ptr [ebp-4]
0040119F   mov         byte ptr [edx],0
29:           buf=buf+pos+1;
004011A2   mov         eax,dword ptr [ebp-4]
004011A5   mov         ecx,dword ptr [pos (004299b8)]
004011AB   lea         edx,[ecx+eax+1]
004011AF   mov         dword ptr [pos (004299b8)],edx
30:
31:       }
32:   rek:    return re;
004011B5   mov         eax,dword ptr [ebp-8]

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -