Thread: scanf

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Question scanf

    Hey!
    How does this work:

    Code:
    scanf("%[^\n]", x)
    Like what does this >>>>%[^\n]<<<< do? I mean, how does it work?

    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    anything but a newline.
    google regular expresions

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    >google regular expresions
    scanf doesn't have regular expressions.
    These are scan sets ( or inverted scan sets if they begin with a ^ )

    > Like what does this >>>>%[^\n]<<<< do? I mean, how does it work?
    Think of %s being similar to %[^ \t\r\n]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    %[^\n]
    what this basically saying is read anything from the input buffer other than '\n' char

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 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