scanf right square bracket

Discussion in 'C++' started by prodziedzic@gmail.com, May 4, 2007.

  1. Guest

    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?
    , May 4, 2007
    #1
    1. Advertising

  2. wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, May 4, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wabiloo
    Replies:
    1
    Views:
    819
    Martin Honnen
    Jan 25, 2008
  2. Replies:
    1
    Views:
    2,211
    Pavel Lepin
    Mar 14, 2008
  3. winterTTr
    Replies:
    2
    Views:
    345
    winterTTr
    Apr 29, 2009
  4. Asen Bozhilov

    Square bracket and dot notations?

    Asen Bozhilov, Jun 11, 2011, in forum: Python
    Replies:
    4
    Views:
    1,016
    Terry Reedy
    Jun 11, 2011
  5. daveyand
    Replies:
    4
    Views:
    440
    Tad McClellan
    May 24, 2006
Loading...

Share This Page