Powered by Blogger.

File Handling in C



File Handling in C


File Handling in C is used for permanent storage of data. A file represents a sequence of bytes on the disk where a group of related data is stored. It is used to open, store, read, search or close files.

What is File in C ?

A collection of data or information is known as file. A file is a collection of bytes on secondary storage
device such as hard disk .

Example of File Handling in C


#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fptr;
int roll_no;
char stu_name[50];
fptr = fopen("student.txt", "w+");/*  open for writing */
//student .txt is a file in which is used  for store the data
if (fptr == NULL)
{
printf("File does not exists \n");
return;
}
printf("Enter the Rollno\n");
scanf("%d", &roll_no);
fprintf(fptr, "Rollno= %d\n", roll_no);
printf("Enter the name \n");
scanf("%s", stu_name);
fprintf(fptr, "Name= %s\n", stu_name);
fclose(fptr);
}

Output

Enter Rollno 11 Enter the name Faiz

When we open the student.txt file then it contains-
Rollno = 11
Name = Faiz





facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09