by Dinesh Thakur Category: File Handling

Function clearerr ()

The function prototype is as given below.

void(clearerr(FILE* Stream);

 
by Dinesh Thakur Category: File Handling

Function putw()

This function writes an integer (whole number) into a file. The prototype of the function is as shown below.

 
by Dinesh Thakur Category: File Handling

Appending to a file means adding at the end of the file while keeping the previous contents of the file intact. For this the file open mode is "a". Program illustrates appending a file.

 
by Dinesh Thakur Category: File Handling

The function prototype is written in the following manner:

int ungetc(int c, File *stream);

 
by Dinesh Thakur Category: File Handling

The prototype of this function is given below.

int remove(const char* filename);

 
by Dinesh Thakur Category: File Handling

This function is used to change the name of file. Its prototype may be written as given below.

 
by Dinesh Thakur Category: File Handling

This function may be used for opening a file in different modes. The function prototype may be written in the following manner:

 
by Dinesh Thakur Category: File Handling

To read a string in a file we can use fgets () whose prototype is:

char * fgets (char * str, int size, FILE * fp);

 
by Dinesh Thakur Category: File Handling

Let us define a structure student to store the HSC marks data of a student as follows:

 
by Dinesh Thakur Category: File Handling

The fscanf () function works as scanf (). The difference is that fscanf () reads a file and not the computer keyboard. prototype:

int fscanf (FILE * fp, char * str, ...);



 
by Dinesh Thakur Category: File Handling

If a character read from an input stream is not appropriate for the current operation, we can push it back to the stream using the ungetc function. A subsequent character read operation (such as fgetc or getc) on that stream will return this character. The prototype of the ungetc function is given below.

 
by Dinesh Thakur Category: File Handling

The fgets function reads a sequence of character, i. e., a character string from an input stream. Its prototype is given below.

 
by Dinesh Thakur Category: File Handling

The fputc function and putc macro are used to write a character to an output stream. Their prototypes are given below.

 
by Dinesh Thakur Category: File Handling

Let us use a while loop in conjunction with the getc macro to read a text file character by character as explained in Program. The counting of characters and lines is very straight forward, the code for which is given below.

 
by Dinesh Thakur Category: File Handling

When I/O operations on a file are complete, we must close the file using the fclose function. The prototype of this function is as follows:

 
by Dinesh Thakur Category: File Handling

The devices used with a computer, such as a keyboard, monitor, printer, hard disk, magnetic tape, etc., have widely varying properties regarding data input and output. To simplify data I/O operations, the C standard library supports a simple mode of input and output based on the concept of a stream.



 
by Dinesh Thakur Category: File Handling

The getw and putw functions, The fprintf & fscanf functions, Random access to files and fseek function. C supports a number of functions that have the ability to perform basic file operations, which include:

 
by Dinesh Thakur Category: Puppetting On Strings

A string is defined to be an array of characters. If it is desired to have an array of strings such as a list of names, it becomes similar to an array whose elements are also arrays. Therefore, an array of strings is a two-dimensional array; it may be declared as below.

 
by Dinesh Thakur Category: Puppetting On Strings

In C language, a string is defined as a variable length array of characters terminated by the null character ('\O'). Letters such as A, b, C, etc., digits such as 1, 2, 3, etc., and special symbols such as +,- ,*, [] , () , etc., except a few control characters, may be included in a string. The various functions of C Standard Library for manipulation of strings are contained in header file <string.h>.

 
by Dinesh Thakur Category: Puppetting On Strings

The function dstr_read given below reads a string from the keyboard into array buf, stores it in dynamically allocated memory and returns a pointer to it.

 

Page 15 of 16



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.