Securing Higher Grades Costing Your Pocket? Book Your Assignment at The Lowest Price Now!

  • +1-617-874-1011 (US)
  • +44-117-230-1145 (UK)
Online Customer Service
Follow Us:

File Handling In C

In the earlier chapters we have seen that when we want to give Input or take Output in the program, we do it using consol. In this chapter we will learn to make Input or output using an external file in the C Program.

Following are the various operations we can perform on a file:

  1. Creation of a file
  2. Opening an existing file
  3. Reading from a file
  4. Writing data to the file
  5. Closing a file

In order to read or write using a file in C, we must open the file first using fopen(). In fopen() function, we provide the name of the file and the mode in which file must be opened. When an ‘r’ is used, the file is opened for reading, a ‘w’ is used to indicate a file to be used for writing and an ‘a’ indicates that you desire to append additional data to the data already in an existing file. The job of actually outputting to the file is nearly identical to the outputting we have already done to the standard Output Device.

File Handling In C Homework Help

Reading from a text file

#include <stdio.h>
main( )
{
FILE *fp;
char c;
funny = fopen("README.TXT", "r");
if (fp == NULL)
printf("File doesn't exist\n");
else
{
do {
c = getc(fp); /* get one character from the file */
putchar(c); /* display it on the monitor */
} while (c != EOF); /* repeat until EOF (end of file) */
}
fclose(fp);
}

Topics in C Programming

PLACE ORDER NOW
captcha image 

Resources

  •   24 x 7 Availability.
  •   Trained and Certified Experts.
  •   Deadline Guaranteed.
  •   Plagiarism Free.
  •   Privacy Guaranteed.
  •   Free download.
  •   Online help for all project.
  • Need Assignment Help

Testimonial

Urgenthomework helped me with finance homework problems and taught math portion of my course as well. Initially, I used a tutor that taught me math course I felt that as if I was not getting the help I needed. With the help of Urgenthomework, I got precisely where I was weak:
Read More

Tap to Chat
Get Instant Assignment Help
Tap to Chat
Get Instant Assignment Help