strtok() 和空字段 [英] strtok() and empty fields

查看:28
本文介绍了strtok() 和空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些 C 结构序列化为字符串,然后使用 strtok() 将其反序列化.但是,不幸的是,strtok() 不检测空字段(例如 1:2::4).

I am serializing some C structure to string and than deserializing it with strtok(). But, unfortunately, strtok() don't detect empty fields (eg 1:2::4).

有什么替代功能吗?

推荐答案

在 linux 上有 strsep.

On linux there's strsep.

引入了 strsep() 函数作为 strtok() 的替代品,因为后者不能处理空领域.然而,strtok()符合C89/C99,更便携.

The strsep() function was introduced as a replacement for strtok(), since the latter cannot handle empty fields. However, strtok() conforms to C89/C99 and hence is more portable.

这篇关于strtok() 和空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆