Write a C Program that makes a copy of a file using standard I/O and system calls.
AIM:
Write a C Program that makes a copy of a file using standard I/O and system calls.
Program:
#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); }
Output:
student@ubuntu:~$gcc –o prg10.out prg10.c student@ubuntu:~$cat > ff hello hai student@ubuntu:~$./prg10.out ff hello hai
-
UpdatedOct 23, 2014
-
Views34,499
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.