E
Elephant
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int fd1, n;
char sl;
if (argc < 2) {
printf("Koristenje: vjezba4 <ime_datoteke>\n");
exit(0);
}
fd1=open(argv[1], O_RDONLY);
if (fd1 < 0) {
perror("open");
exit(-1);
}
while((n=read(fd1, &sl, 1)) > 0) {
write(STDOUT_FILENO, &sl, 1);
}
if (n == -1) {
perror("read");
}
close(fd1);
exit(0);
}How to extend this code for doing "cat"program starts by entering a file
name or more of them unless it s started with one filename it prints the
source of the file. If there is no filename in program the stdin will copy
the stdout
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int fd1, n;
char sl;
if (argc < 2) {
printf("Koristenje: vjezba4 <ime_datoteke>\n");
exit(0);
}
fd1=open(argv[1], O_RDONLY);
if (fd1 < 0) {
perror("open");
exit(-1);
}
while((n=read(fd1, &sl, 1)) > 0) {
write(STDOUT_FILENO, &sl, 1);
}
if (n == -1) {
perror("read");
}
close(fd1);
exit(0);
}How to extend this code for doing "cat"program starts by entering a file
name or more of them unless it s started with one filename it prints the
source of the file. If there is no filename in program the stdin will copy
the stdout