Search This Blog

C Program to Open, Read and Write a file using System Calls

This is a C program to open , read and write files using system calls in Linux (UNIX) operating systems. The system calls open(), read() and write() are used in the C program to open, read and write files in Unix/Linux operating systems.

#include<stdio.h>
#include<fcntl.h>
main()
{


char buff[100],fn[10];
int fd,n;
printf("Enter file name\n");
scanf("%s",fn);
fd=open(fn,O_RDONLY);
n=read(fd,buff,100);
n=write(1,buff,n);
close(fd);
}

No comments: