You just need to 'consume' the '
' character after you've read what you want. Use the following format directive
Which will read everything up to the newline into the string you pass in, then will consume a single character (the newline) without assigning it to anything (that '*' is 'assignment suppression').
Otherwise,the newline is left in the input stream waiting to immediately terminate the the subsequent "%[^
]" format directives.
The problem with adding a space character to the format directive (" %[^
]") is that the space will match any white space. So, it will eat the newline from the end of the previous input, but it will also eat any other whitespace (including multiple newlines).