Text and Binary Streams in C

Question: What are Text and Binary Streams in C?

Answer: There are two types of streams in C: Text streams and Binary streams. Text streams may have certain characteristics that may vary from system to system. One of these is maximum length of text line. Though standard defines it to be at least 254 characters other implementations might define this differently. Another characteristic is the manner in which a line is terminated. Notice that a text line on MS-DOS system is terminated with a carriage return/newline character pair. On UNIX and LINUX system, line terminates with a newline character.

Notice that standard defines a text line to be zero or more characters followed by terminating newline character. On implementations, for ex. MS-DOS, where external representation of text line differs from this definition, library functions take care of translating between external and internal forms. A text line on MS-DOS system is terminated with carriage return/newline character pair. Carriage return character is discarded while reading from a file on MS-DOS and carriage return is added with newline when data is being written to MS-DOS. The ability to manipulate the text without regard to external appearance simplifies creation of portable programs.

Bytes in binary stream are written to the file or device exactly as program wrote them and are delivered to the program exactly as they were read form file or device. Nothing is changed in any manner. This type of stream is useful for non-textual data. Yet, this stream can be used for textual data as well when we don’t want library functions to modify end-of-line characters.

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.