Is scanf’s “regex” support a standard? I can’t find the answer anywhere.
This code works in gcc but not in Visual Studio:
scanf("%[^\n]",a);
It is a Visual Studio fault or a gcc extension ?
EDIT: Looks like VS works, but have to consider the difference in line ends between Linux and Windows.(\r\n)
That particular format string should work fine in a conforming implementation. The
[character introduces a scanset for matching a non-empty set of characters (with the^meaning that the scanset is an inversion of the characters supplied). In other words, the format specifier%[^\n]should match every character that’s not a newline.From C99 7.19.6.2, slightly paraphrased:
It’s possible, if MSVC isn’t working correctly, that this is just one of the many examples where Microsoft either don’t conform to the latest standard, or think they know better 🙂