Skip to main content
edited title
Link
Joseph
  • 3
  • 1
  • 4

C Programming - Reading from stdin and storing \n and whitespace

Source Link
Joseph
  • 3
  • 1
  • 4

C Programming - Reading from stdin and storing \n and whitespace

I've been trying to use scanf to get input from stdin but it truncates the string after seeing whitespace or after hitting return.

What I'm trying to get is a way to read keyboard input that stores in the buffer linebreaks as well as whitespace. And ending when ctrl-D is pressed.

Should I try using fgets? I figured that wouldn't be optimal either since fgets returns after reading in a \n