gcht101hello/code20240720.html 20240720
Sorce Code:WECP100/catc02.c
hello

// WECP100/catc02.c 20240720
// description: simple cat using system call, without Error Handling
// machine: laptop window11
// os: linux using wsl on windows11
// > wsl on power shell
// cat /etc/os-release >> PRETTY_NAME="Ubuntu 22.04.2 LTS"
// uname -a >> inux LAPTOP-2E5CQCBT 6.6.36.3-microsoft-standard-WSL2 #1
//          >> Sat Jun 29 07:01:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
// language: g++ --version, g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 
//$ g++ catc02.cpp -o catc02
//$ ./catc02 
//  ./catc02 text.txt  >>  1234567890
#include 
#include 
int main(int argc, char *argv[]){
    char buffer[2048];                     // buffer size:2048  
    int  fileCat = open(argv[1], O_RDONLY);//open fd:File Descriptor argv[1] read only  
    int  n = read(fileCat, buffer, 2048);  // read fd  buffersize:2048
    write(1, buffer, n);                   // write fd STDOUT_FILENO:1
    close(fileCat);                        // close File Descriptor  
}