Error[8]: Undefined offset: 3, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '[+++]';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '[+++]')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '[+++]';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

[+++]

运行环境 VS2022,结果如下:

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '[+++]')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '[+++]';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

[+++]

运行环境 VS2022,结果如下:

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '[+++]';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

[+++]

运行环境 VS2022,结果如下:

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

[+++]

运行环境 VS2022,结果如下:

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 7, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

 

运行环境 VS2022,结果如下:

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
C语言之strtok函数模拟实现_C_内存溢出

C语言之strtok函数模拟实现

C语言之strtok函数模拟实现,第1张

C初学者,仅作为学习笔记,不喜勿喷,当然提建议是很欢迎的,我会虚心求教的,还望不吝赐教。

废话不多说,直接上代码.....

/*模拟实现strtok字符串切割函数*/
char* my_strtok(char* strToken, const char* strDelimit)
{
	char* str1 = strToken;
	char* temp = NULL;
	char* str2 = (char*)strDelimit;
	static char* pos = NULL;

	if (str1 != NULL)
	{
		while (*str1)
		{
			str2 = (char*)strDelimit;
			while (*str2 != '/*对my_strtok字符串切片函数的测试*/
void Test09(void)
{
	char arr[] = "www.baidu.com and 1808743108@qq.com";
	const char* sep = ". @";
	
	char arrcpy[40];

	printf("The sep is :%s\n", sep);

	/*由于strtok会破坏原字符串的结构,所以通常会拷贝一份用来切割*/
	my_strcpy(arrcpy,arr);
	printf("arrcpy = %s\n", arrcpy);

    printf("--------------------------------------\n");
	char* str = my_strtok(arr, sep);
	if(str!=NULL)
		printf("%s\n", str);
	while ((str = my_strtok(NULL, sep)) != NULL)
	{
		printf("%s\n", str);
	}
}')
			{
				if ((*str1 == *str2))
				{
					if (*(str1 + 1) == 'The sep is :. @                        //切割字符为'.' 、'空格'、'@'。
arrcpy: www.baidu.com and 1808743108@qq.com
--------------------------------------
www
baidu
com
and
1808743108
qq
com

E:\桌面\学习\C project\StringFuncation\Debug\StringFuncation.exe (进程 28700)已退出,代码为 0。
按任意键关闭此窗口. . .')
						pos = NULL;
					else
						pos = str1;
					*str1 = '';
					return strToken;
				}
				str2++;
			}
			str1++;
		}
	}
	else
	{
		if (pos != NULL)
		{
			str1 = pos + 1;
			temp = pos + 1;
			while (*str1)
			{
				str2 = (char*)strDelimit;
				while (*str2 != '')
				{
					if ((*str1 == *str2))
					{
						pos = str1;
						*str1 = '';
						return temp;
					}
					str2++;
				}
				str1++;
			}
			pos = NULL;
			return temp;
		}	
	}
	return NULL;
}

以下是测试程序:

 

运行环境 VS2022,结果如下:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/3002690.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-27
下一篇 2022-09-27

发表评论

登录后才能评论

评论列表(0条)

保存