gcht101hello/code20240806.html 20240806
Sorce Code:WWECP100/filecp.c
hello
    
    //WWECP100/filecp.c
    //decription: file copy on linux
    //machine: WSL on window11
    //os: PRETTY_NAME="Ubuntu 22.04.2 LTS"
    //language: c++,  g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
    //> wsl
    //$ cd /mnt/c/Users/miura/Documents/62WECP100
    //$ nano filein.txt >>  input text
    //$ cat filein.txt  filedin.txt 0123456789
    //$ gcc filecp.c -o filecp
    //$ ./filecp >> filedin.txt 0123456789
    //$ time ./filecp 
    // filedin.txt 0123456789
    // real    0m0.024s
    // user    0m0.000s
    // sys     0m0.005s
    //$ cat fileout.txt
    // filedin.txt 0123456789
    #include< stdio.h> //for fgetc, fputc, and putchar
    int main(void) {
      FILE *fi = fopen("filein.txt", "r");  // open file  "r" for reading 
      FILE *fo = fopen("fileout.txt", "w"); // open file  "w" for writing
      // if (fi == NULL || fo == NULL) {   // handing error
      //   fprintf(stderr, "Error opening files.\n");
      //   return 1;
      // }
    while (1) {
      int readChar = fgetc(fi);    // read Char
      if (EOF == readChar) break;  // check end-of-file:EOF 
      fputc(readChar, fo);         // write file 
      putchar(readChar);           // write stdout
    }//end while 
      fclose(fi); //Closing files
      fclose(fo); //Closing files
    }//end main
    
//--------------------------------------------------