I've got some analysis code (myprog
) that sucks in data using the following:
if(5 == fscanf(in, "%s%lf%f%f%f", tag, & sec, & tgt, & s1, & s2))
which works just fine. But in the situation where I've got data files that are separated by co开发者_StackOverflow中文版mmas, I'm currently doing something like:
sed 's/,/ /g' data | myprog
Can I modify the format string in the fscanf()
function to accept both delimitation formats?
fscanf(in, "%[^, ]%*[, ]%lf%*[, ]%f%*[, ]%f%*[, ]%f", tag, &sec, &tgt, &s1, &s2)
Should work?
What about this:
char tmp; fscanf(in, "%s%c%lf%c%f%c%f%c%f", tag, &tmp, & sec, &tmp,& tgt, &tmp,& s1, &tmp, & s2)
If you are not going to care what single character delimits your values, just read it and store it in a throw-away variable.
精彩评论