How do I parse out the fields in a comma separated string using sscanf while supporting empty fields?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a comma separated string which might contain empty fields. For example: 1,2,,4 Using a basic sscanf(string,"%[^,],%[^,],%[^,],%[^,],%[^,]", &val1, &val2, &val3, &val4); I get all the values prior to the empty field, and unexpected results from the empty field onwards. When I remove the expression for the empty field from the sscanf(), sscanf(string,"%[^,],%[^,],,%[^,],%[^,]", &val1, &val2, &val3, &val4); everything works out fine. Since I don't know when I'm going to get an empty field, is there a way to rewrite the expression to