File Handling and its basics

File Handling and its basics

It's been almost 2 weeks since i have posted a “Basics of C” post So here it is and today’s topic for discussion is “File Handling ''. By the end of this post you will be able to answer the following question:-

1.What is File Handling? 2.What are the different file operations performed using this?

So far the functions we have performed up until now in C language are not stored anywhere but so is not the case in real life, during jobs data is stored and one of the ways it can be stored is in files and folders.

File handling in C enables us to create, update, read, and delete the files stored on the local file system through our C program. The following operations can be performed on a file:-

Creating a file Opening a file Reading from a file Writing in a in a file Deleting a file

Different function used under file handling are:-

fopen-To open an existing or a new file.

fopen(“fileName.txt”, “mode”)

fclose-Closes the file

fclose(FILE* fp)

fprintf-To enter data into the file

fprintf(file pointer,"%s %d",data(array,string,char,int))

fscanf-To read data from the file

    fscanf(FILE *stream, const char *format [, argument, ...])

Fputc-To write character into the file

    fputc(int c, FILE *stream)

fgetc-To read character from the file

fgetc(File pointer)

For the live application or use of the above you can refer to my github repository- github.com/harsh007-github