C Program that makes a copy of a file using standard I/O and system calls

				
					#include <stdio.h>

#include <unistd.h>

#include <fcntl.h> 

void typefile (char *filename)

 { 

int fd, nread; 

char buf[1024];

fd = open (filename, O_RDONLY); 

if (fd == -1) 

{ 

perror (filename); 

return; 

}

while ((nread = read (fd, buf, sizeof (buf))) > 0)

 write (1, buf, nread); 

close (fd);

 }

int main (int argc, char **argv) 

{ 

int argno; 

for (argno = 1; argno < argc; argno ) 

typefile (argv[argno]); 

exit (0); 

}
				
			

Leave a Reply