scanf doubt

This is a discussion on scanf doubt within the C Programming forums, part of the General Programming Boards category; scanf("%s[^\n]%*c",rule[i]) what does it mean?...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    1

    scanf doubt

    scanf("%s[^\n]%*c",rule[i])

    what does it mean?

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    847
    I don't think it does what the programmer intended. I suspect it was supposed to be something like
    Code:
     scanf("%31[^\r\n]%*[\t\n\v\f\r ]", rule[i])
    assuming rule[i] has space for at least 32 chars (31 plus the trailing '\0').

    scanf("%s[^\n]%*c", rule[i]) means:
       %s         Read a string up to the next whitespace, hoping that the buffer is long enough
       [^\n] Expect [ followed by a ^ followed by any amount of whitespace, including none, then ]
       %*c       Consume one character of input, but don't save it anywhere

    On the other hand, scanf("%31[^\r\n]%*[\t\n\v\f\r ]", string) means:
       %31[^\r\n]            Read up to 31 characters (not newlines, CR or LF)
       %*[\t\n\v\f\r ] Read all newlines and whitespace characters, but don't store them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt on scanf function
    By vandrea in forum C Programming
    Replies: 2
    Last Post: 09-13-2009, 11:25 AM
  2. Doubt in c
    By kanagu_raj82 in forum C Programming
    Replies: 4
    Last Post: 01-10-2007, 10:22 AM
  3. Scanf Doubt
    By Maragato in forum C Programming
    Replies: 7
    Last Post: 02-09-2005, 12:03 PM
  4. First scanf() skips next scanf() !
    By grahampatten in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:47 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21