I want use scanf to read from input everything till right square
bracket ']'.
It seems to be something like that:
scanf("%[^\]]) but that's not working.
Any ideas?
A couple. First, 'comp.lang.c' is a [marginally] better place
to ask about the functionality of C standard library functions.
Second, have you tried using 'getline' and parse the input line
yourself? 'string' has plenty of functionality to locate your ']'
and trim the input. Third, the C standard says that the right
bracket has to be the first in your sequence to be considered in
it, IOW, the sequence has to be "%[^]]" if you want to read any
character up to the bracket.
#include <cstdio>
int main()
{
char c[10] = {}, s[] = "123]321";
int i = sscanf(s, "%[^]]", c);
printf("scanned %d fields, c = <%s>\n", i, c);
}
Should print
scanned 1 fields, c = <123>
V