Aim:
Write a C Program to Implement the Concept of I/o Call.
Description:
- creat(name, permissions) – Used to create a file with the name and mode specified. Here, permission would be a number. 0666 means read write permissions.
- open(name, mode) – Used to open a file name in the mode (read or write) specified. 0 is for opening in read mode, 1 for writing and 2 for both.
- close(fd) – Close a opened file.
- unlink(fd) – Delete a file.
- read(fd, buffer, n_to_read) – Read data from a file.
- write(fd, buffer, n_to_write) – write data from to a file.
- lseek(fd, offest, whence) – Move the read/write pointer to the specified location.
Algorithm:
- STEP 1- START
- STEP 2- Declare the value fd
- STEP 3- If file does not have in directory then file foo.txt is created.
- STEP 4- print which type of error have in a code
- STEP 5- print program detail “Success or failure
- STEP 6- STOP
Program:
#include<stdio.h> #include<fcntl.h> #include<errno.h> extern int errno; int main() { int fd = open("foo.txt", O_RDONLY | O_CREAT); printf("fd = %d/n", fd); if (fd ==-1) { printf("Error Number % d\n", errno); perror("Program"); } return 0; }
Result:
Thus Input and Output system call program was executed Successfully