Monthly Archive: December 2013

Closing the File in C 2

Closing the File in C

Once we open a file, finished reading from the file, we need to close the file. This is done using the function fclose() through the statement: fclose(fp); Once we are done with closing the file, we can no longer read, write or perform any operation on the file unless we reopen it.  Note that to close the file, we don’t use the filename but the file pointer fp. On closing the file, the buffer associated with the file is removed from memory. While performing a write operation on a file, when we try to close the file using fclose(), three...

Reading from a File in C 2

Reading from a File in C

Once the file has been opened for reading using fopen(), as we have seen, the file’s contents are brought into buffer and a pointer is set up that points to the first character in the buffer. This pointer is one of the elements of the structure to which fp is pointing. To read the file’s contents from the memory, there exists a function called fgetc(). This has been used in our program as: ch = fgetc(fp); fgetc() performs the following operations: Reads the characters from the current pointer position Advances the pointer position so that it now points to the next character...

Opening a file in C 2

Opening a file in C

We can perform read and write operations on a file in C. But, before that we must open a file. To open a file in C, we have to call the function fopen() as shown below: FILE *fp; fp = fopen(“file1.C”,”r”); The above statement would open file named “file1.C” in “read” mode. It tells the computer that the file being opened would be used for reading purpose only. fopen() performs three important tasks when you open the file in “r” mode: Firstly, it searches the file to be opened on the disk Then it loads the file from the disk into...

Introduction to File Operations in C Programming language 4

Introduction to File Operations in C Programming language

As we all know, the operations we perform via. printf and scanf, reads and stores data in the memory. But this memory is limited for use. If in case we need to read and store large amount of data then this limited memory can’t be used. We need to find some ways to store this data permanently so that we can read and write to it at later point of time. This is where file operations comes into picture. C provides us with the facility to perform File operations in C programming language. File Operations in C Programming Language: There...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet