Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Operating Systems Lab Manual
/ OS Directory system call C Program
Program Name
Write a C Program to write data to a file and read it using Dirctory system calls
Theory
Dirctory system calls are used to write data to a file.
Program Code
Copy Program Code
#include
#include
#include
#include
int main() { int fd; char ch='y'; fd=open("f1",O_CREAT|O_WRONLY,0666); if(fd==-1) perror("file cannot be opend"); do { read(0,&ch,1); if(ch=='n') break; write(fd,&ch,1); }while(ch!='n'); close(fd); fd=open("f1",O_RDONLY); while(read(fd,&ch,1)!=0) write(1,&ch,1); close(fd); return 0; }
Input:
a1 b1 n
Output:
a1 b1
Home
Back