#include <bits/stdc++.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
int main() {
    ssize_t n;
    int fd;
    char buff[50];
    cout << "Enter text to write in the file:" << endl;
    n = read(STDIN_FILENO, buff, sizeof(buff));  // Read from standard input

    fd = open("A.txt", O_CREAT | O_RDWR, 0777);  // Open/create file with read/write permissions
    if (fd < 0) {
        perror("File open error");  // Error handling
        return 1;
    }
    write(fd, buff, n);    // Write input to file
    write(STDOUT_FILENO, buff, n);  // Write input back to standard output
    close(fd);
    return 0;
}