I/O System Call in C Program with Examples

I/O system calls:

  • Open
  • Close
  • Read
  • Write

Program:

	#include<stdio.h>	
	#include<sys/types.h>
	#include<sys/stat.h>
	#include<fcntl.h>
	#include<stdlib.h>*/
	int main(int argc, char *argv[])
	{
		int n, fd;
		char buff[50];
		fd=open(argv[1],0);
		if(fd!=-1)
		{
			while ((n=read(fd, buff, sizeof(buff)))>0)
				write (1, buff, n);
		}
		close(fd);
}

Output:

$cc -o iocall.out iocall.c
$ ./iocall.out fork.c

Leave a Comment