#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

int main(void) {
int infd, outfd, i, count;
char buf[128], buf1[128];

printf("Enter str:"); gets(buf);
if ((infd = open("/etc/passwd", O_RDONLY)) == -1) {
	perror("/etc/passwd"); exit(1); }
if ((outfd = open("testfile.txt", O_WRONLY | O_CREAT, 0644)) == -1) {
	perror("testfile.txt"); exit(1); }
gets(buf1);
count = read(infd, buf1, 100); buf[count] = '\0'; puts(buf1);
for (i = 0; i < 5; i++) {
	gets(buf1); write(outfd, buf, strlen(buf));
}

close(infd);
close(outfd);
return 0;
}
