scanf

This is a discussion on scanf within the C Programming forums, part of the General Programming Boards category; Hey! How does this work: Code: scanf("%[^\n]", x) Like what does this >>>>%[^\n]<<<< do? I mean, how does it work? ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    >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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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, 07: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, 05:34 AM

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