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);
<
The "%[" format spec for scanf() is standard and has been since C90.
MSVC does support it.
You can also provide a field width in the format spec to provide safety against buffer overruns:
int main()
{
char buf[9];
scanf("%8[^\n]",buf);
printf("%s\n", buf);
printf("strlen(buf) == %u\n", strlen(buf));
return 0;
}
Also note that the "%[" format spec doesn't mean that scanf() supports regular expressions. That particular format spec is similar to a capability of regexs (and no doubt was an influenced by regex), but it's far more limited than regular expressions.