Question: I'd like to skip any semicolon or new line char before reading from char array. I wrote code like this:

```
char[] buf;
// buf initialized
double val = 0.0;
sscanf(buf, "%[;\n]%lf", &val);

```

But it won't work if there is no semicolon or new line sign on the beginning of buf. How can I change that code to skip that two chars only if they're present?

edit: `sscanf(buf, "%*[;\n]%lf", &val);` also does not work.

tested sample buf value: "67.445906;20.239875;89.577929;6.350902;7.788324\n19.806513;69.875179;"

edit2: I read on [C++ reference](http://www.cplusplus.com/reference/cstdio/scanf/), in section about specifiers, that "Except for %n, at least one character shall be consumed by any specifier. Otherwise the match fails, and the scan ends there."

Answer: 
Assuming you're writing in C you can try that solution.

```
double val = 0.0;
char buf[] = "67.445906;20.239875;89.577929;6.350902;7.788324\n19.806513;69.875179;";
char * ptr;
ptr = strtok(buf, ";\n");

while (ptr != NULL) {
    // Here you iterate on different val, in this example we print them
    printf ("%lf\n", &val);
    ptr = strtok (NULL, " ,.-");
}

```

As Zack said it's better avoiding sscanf when possible.
You have discovered one of the many reasons why `*scanf` should never be used: the ridiculous difficulty of getting it to cope with real file formats. (Other important reasons include how easy it is to write constructs that *look* sane but are every bit as dangerous as `gets`, and the fact that numeric overflow causes undefined behavior.)

Instead, use `strtok` (or, better, `strsep` if you have it) to split up the line buffer at semicolons, then `strtod` to convert numbers to binary.