0% found this document useful (0 votes)
5 views2 pages

EXPT1

The document contains multiple C code snippets demonstrating file operations including opening, reading, writing, and closing files. It shows how to handle errors using errno and the perror function. Each code snippet is designed to perform specific tasks related to file handling in C.

Uploaded by

tushartiwari1648
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

EXPT1

The document contains multiple C code snippets demonstrating file operations including opening, reading, writing, and closing files. It shows how to handle errors using errno and the perror function. Each code snippet is designed to perform specific tasks related to file handling in C.

Uploaded by

tushartiwari1648
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

INPUT OF OPEN C:

#include<stdio.h>
#include<fcntl.h>
#include<errno.h>
extern int errno;
int main()
{
int fd = open("os1.txt", O_RDONLY | O_CREAT);
printf("fd = %d \n ", fd);
if(fd == -1)
{
printf("Error Number %d \n", errno);
perror("Program");

return 0;

OUTPUT:

INPUT FOR READ C:


#include<unistd.h>
int main()
{
char buff[20];
read(0,buff,10);
write(1,buff,10);
}

OUTPUT:
INPUT FOR WRITE C:
#include<unistd.h>
int main()
{
write(1,"HELLO BUDDY\n", 12);
}

OUTPUT:

INPUT FOR CLOSE C:


#include<stdio.h>
#include<fcntl.h>
#include<errno.h>
extern int errno;
int main()
{
int fd = open("os2.txt", O_RDONLY | O_CREAT);
printf("fd = %d \n ", fd);
if(fd == -1)
{
printf("Error Number %d \n", errno);
perror("Program");

return 0;

}
OUTPUT:

You might also like