Category: File Input Output

File Input Output

Merging two files in one in C/C++

Merging two files in one in C/C++

We are opening first file firstFile.txt secondly file secondFile.txt and then reading line by line both of these files and writing a line of first file to third file and then contents of first...

Command Line Arguments in C

Command Line Arguments in C

Using argc and argv To execute the file-copy programs we are required to first type the program, compile it, and then execute it. This program can be improved in two ways: (a) There should...

Text Files and Binary Files

Text Files and Binary Files

A text file contains only textual information like alphabets, digits and special symbols. In actuality the ASCII codes of these characters are stored in text files. A good example of a text file is...

Record I/O in Files

Record I/O in Files

So far we have dealt with reading and writing only characters and strings. What if we want to read or write numbers from/to file? Furthermore, what if we desire to read/write a combination of...

File Opening Modes in C

File Opening Modes in C

In our first program on disk I/O we have opened the file in read (“r”) mode. However, “r” is but one of the several modes in which we can open a file. Following is...

Writing to a File

Writing to a File

The fputc( ) function is similar to the putch( ) function, in the sense that both output characters. However, putch( ) function always writes to the VDU, whereas, fputc( ) writes to the file....

File Copying in C

File Copying in C

We have already used the function fgetc( ) which reads characters from a file. Its counterpart is a function called fputc( ) which writes characters to a file. As a practical use of these...

Closing the File

Closing the File

When we have finished reading from the file, we need to close it. This is done using the function fclose( ) through the statement, Once we close the file we can no longer read...

Trouble in Opening a File

Trouble in Opening a File

There is a possibility that when we try to open a file using the function fopen( ), the file may not be opened. While opening the file in “r” mode, this may happen because...

Reading Files in C

Reading Files in C

Once the file has been opened for reading using fopen( ), as we have seen, the file’s contents are brought into buffer (partly or wholly) and a pointer is set up that points to...

Opening a File

Opening a File

Before we can read (or write) information from (to) a file on a disk we must open the file. To open the file we have called the function fopen( ). It would open a...

File Operations

File Operations

There are different operations that can be carried out on a file. These are: (a)Creation of a new file (b)Opening an existing file (c)Reading from a file (d)Writing to a file (e)Moving to a...

Communicating with Files

Communicating with Files

Often you need programs that can read information from files or can write results into a file. One such form of program-file communication is file redirection, This method is simple but limited. For example,...

No © Loop and Break