#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
	int input;
	int written_bytes;
	printf("Hello, I am files.c\n");
	
	// writing to the standard out
	
	int file_rd=fileno(stdin);  /* filedescriptor = 0 */
        int file_wr=fileno(stdout); /* filedescriptor = 1 */
	//int id = open()
        written_bytes = write(file_wr, "test", 4);
	fsync(file_wr);
	//printf("Written bytes:%d", written_bytes);
	
	
	// creating a file and write something in it
	int fileno = open("filetowrite", O_CREAT | O_WRONLY | O_TRUNC);
	written_bytes = write(fileno, "write", 5);
	close(fileno);
	
	// opening a file for reading and reading from it
	int fileno2 = open("filetowrite", O_RDONLY);
	char buffer[100];
	int characters_read = read(fileno2, buffer, 100);
	buffer[characters_read] = 0;
	printf("Characters read:%d\n", characters_read);
	printf("String read was <%s>\n", buffer);
}
