sscanf分割字符串
参考自这里
例如字符串str
为:x = 10
,我想利用sscanf
切割key = 'x'
和value = 10
,但是直接用下面这种方式不太行:
sscanf(str, "%s=%s", cBufferKey, cBufferValue);
这种方式导致解析出来cBufferValue
为空。正确方式应该是这样:
sscanf(str, "%[^s]=%s", cBufferKey, cBufferValue);
参考自这里
例如字符串str
为:x = 10
,我想利用sscanf
切割key = 'x'
和value = 10
,但是直接用下面这种方式不太行:
sscanf(str, "%s=%s", cBufferKey, cBufferValue);
这种方式导致解析出来cBufferValue
为空。正确方式应该是这样:
sscanf(str, "%[^s]=%s", cBufferKey, cBufferValue);