Created
February 9, 2016 00:29
-
-
Save djmunro/93f0a018c6b26c02288d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
int main (int argc, char *argv[]) | |
{ | |
int fd; | |
char *file = argv[1]; | |
char buffer [30]; | |
size_t nbytes; | |
ssize_t bytes_read; | |
fd=open(file, O_RDONLY); | |
if (fd!=-1) | |
{ | |
printf ("file1 opened for read & write access\n"); | |
//sed -n '1,10p' < file1 //Not sure what you're trying to do with this.. but it isn't you want to be doing. | |
nbytes = sizeof(buffer); | |
bytes_read = read(fd, buffer, nbytes); | |
close(fd); //closing file-descriptors is a good thing | |
int od; | |
od = open ("/dev/tty", O_WRONLY); | |
write (od, buffer, bytes_read); | |
close(od); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment