READING FORM A FILE USING C PROGRAM

AIM:
To write a c program to read data from a file.
ALGORITHM:
· Open the file s.dat in read mode.
· Read the data such as name, regno, mark1, mark2.
· Close the file using close() function.
· Terminate the program.


PROGRAM SOURCE CODE OPERATING SYSTEM (OS) LAB IN LINUX ENVIRONMENT

#include<fcnt1.h>
struct s_det
{
char name[20];
int regno,m1,m2;
};
main()
{
int fd;
struct s_dets s_rec;
fd=open("s.dat",O_WRONGLY);
if(fd!=-1)
{
while(read(fd,&s_rec,sizeof(struct S_det)))
{
printf("name: %s\n",s_rec.name);
printf("regno:%d\n",s_rec.regno);
printf("mark1:%d\n",s_rec.m1);
printf("mark2:%d\n",s_rec.m2);
}
close(fd);
}
printf("\n end of process");
return 0;
}



CONCLUSION:

Thus the c program to read data from file was written and executed successfully.

Related post