Thread: scanf and a carriage return

  1. #1
    Registered User Fauveboy's Avatar
    Join Date
    Apr 2014
    Posts
    42

    scanf and a carriage return

    if I leave the &dummy and second %c specifier scanf with &note2 gets an error later. is that because without the dummy the second scanf recieves the carriage return? I not sure why &note2 doesnt also need a dummy ?

    scanf and a carriage return-screen-shot-2017-11-30-00-34-13-png

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    You don't need the dummy variables if you simply add a single space before the %c, like this:
    Code:
    scanf(" %c", &note1);
    scanf(" %c", &note2);
    a space in scanf tells it to ignore all whitespace characters, like newline, tab, space etc.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fputs with carriage return?
    By goat37 in forum C Programming
    Replies: 5
    Last Post: 04-19-2011, 06:44 PM
  2. automatic carriage return?
    By A34Chris in forum C Programming
    Replies: 5
    Last Post: 09-17-2007, 08:53 PM
  3. how to accept a carriage return ?
    By mramazing in forum C Programming
    Replies: 5
    Last Post: 01-09-2007, 04:24 PM
  4. carriage return when tokenizing
    By wjday in forum C Programming
    Replies: 6
    Last Post: 11-17-2001, 07:10 AM
  5. _getch() and doing a carriage return
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2001, 02:19 PM

Tags for this Thread