C语言:解决strtok两个连续分隔符当作一个提取的问题

strtok函数使用参考:
https://blog.csdn.net/weixin_38184741/article/details/88844286

解决连续两个分割符当作一个的参考代码:

	int n;
	int tmp_len = len;
	for(n=0; n<tmp_len; n++) //解决:strtok两个连续分隔符当作一个提取的问题
		{
			if(tmp_buf[0] == ';') //第一个字符就是分隔符
				{
					tmp_len++;
					int i;
					for(i=tmp_len; i>0; i--)
						{
							tmp_buf[i] = tmp_buf[i-1];
						}
					tmp_buf[0] = ' ';
				}
			if((tmp_buf[n] == ';') && (tmp_buf[n+1] == ';'))
				{
					tmp_len++;
					int i;
					for(i=tmp_len; i>n; i--)
						{
							tmp_buf[i] = tmp_buf[i-1];
						}
					tmp_buf[n+1] = ' ';
				}
		}
	char *result = NULL;
	int index = 0 ;
	result = strtok( tmp_buf, ";" );
	while( result != NULL )
		{
			switch(index)
				{
				case 0:
				{

					break;
				}
				case 1:
				{

					break;
				}
				case 2:
				{

					break;
				}
				default :
				{
					break;
				}

				result = strtok( NULL, ";" );
				index++;
				}

		}

参考连接:
https://blog.csdn.net/bytxl/article/details/7863081

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值