Q What are the differences between a text stream and a binary stream?
A A text stream is a sequence of characters that may not have a one-to-one relationship with the data on the device. Text streams are normally used for textual data, which have a consistent appearance from one environment to another, or from one machine to another. A binary stream, on the other hand, is a sequence of bytes that has a one-to-one correspondence to those on the device. Binary streams are primarily used for nontextual data that is needed to keep the exact contents on the device.
Q Why do you need a file pointer?
A A file pointer is used to associate a stream with an opened file for reading or writing purposes. A pointer of the type FILE is called a file pointer. FILE is a typedef for a structure that contains overhead information about a disk file. A file pointer plays an important role in the communication between programs and disk files.
Q What does the fclose() function do before it closes an opened file?
A As you know, all high-level I/O operations are buffered. One of the jobs of the fclose() function is to flush data left in the buffer to ensure that no data is lost. For instance, when you finish writing several blocks of characters to an opened text file, you call the fclose() function to disassociate a specified stream and close the text file. The fclose() function will first flush all characters left in the buffer and write them into the text file before it closes the file. In this way, all characters you write to the file will be saved properly.
Q What is the difference between fgets() and gets()?
A The major difference between the fgets() and gets() functions is that the fgets() function includes a newline character in the array if the newline is encountered during the reading, whereas the gets() function just replaces the newline character with a null character.
Question and Answer
Related Items
মডুলার C প্রোগ্রামিং (Modular C Programming)
Programming Style
Programming Style
In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.
Exercises : Answer the following Question
To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.
Question and Answer
Q Is the C preprocessor part of the C compiler?
A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.
Compiling Your Code Under Conditions
Compiling Your Code Under Conditions
You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.