1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help with scanf();

Discussion in 'C' started by lionaneesh, Mar 24, 2010.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Code:
    scanf("%[^\n]",line);
    tell me the logic of this scanf statement and why " [^\n] " is used instead of %s ...
    and how this statement works...

    i know that this statement inputs lines till enter is pressed..

    but what is the format of the scanf statements please tell...
     
  2. karthigayan

    karthigayan New Member

    Joined:
    Feb 19, 2010
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    0
    It is equal to gets . By default scanf will read the input until it receives a word separator ( space,tab,etc ).

    We can change that to some character . Here you changed to read until the new line ( Read the characters other than '\n' .If '\n' it will get end ) .
     

Share This Page