is it possible to know more detailed infos about the buffer in C?
In C there's no difference between a .txt file and the stdin file, but I can access the FILE structure of the .txt (or any other file) but not the stdin's one, why?
When I type a string on my keyboard, is the operating system which inserts in a buffer the string or is the C compiler?
I've looked into the Ritchie's book and in the Deitel's one but I've found nothing about low level understanding of the buffer.
- ?Lv 54 days agoFavorite Answer
stdin, stdout, stderr, are Streams, which are normally linked to a tty device, if you just invoke the executable from the command line.
tty devices are character devices, which generally don't have buffers.
Files, such as a .txt file, reside in a filesystem on block storage device (e.g. /dev/sda1). With a block device you can move the file pointer around to access different parts of the file. So you can do things like seek to the end of the file, then write additional data, or rewide the the beginning of the file and read from there, etc.
But it does not make a lot of sense to rewind the user input from a tty device.
Most of the time you just use the C stdio libraries, and most input devices can be treated in a similar manner. But you do need to be aware of the underlying file types because not all file types support all the operations. For example: fseek() is a stream IO function but if you call it on a character device, I expect you will get an Error return: EBADF: The stream specified is not a seekable stream.