Advertisement
Imran_Mohammed

FILe

Dec 23rd, 2022 (edited)
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.  
  5. // r  read ; w = write ; a = append mode
  6.     FILE *inputFile;
  7.     inputFile = fopen("input.txt" , "r");
  8.  
  9.     if(inputFile == NULL){
  10.         printf("File not found");
  11.         return 0;
  12.     }
  13.  
  14.     FILE *outputFile;
  15.     outputFile = fopen("output.txt" , "w");
  16.  
  17.     while(1){
  18.         char ch = fgetc(inputFile);
  19.         if(ch == EOF){
  20.             break;
  21.         }
  22.  
  23.         fputc(ch , outputFile);
  24.     }
  25.  
  26.     //Use log file for seeing history:
  27.     FILE *logFile;
  28.     logFile = fopen("output.txt" , "a");
  29.     fprintf(logFile , "found at 9.05 pm\n");
  30.  
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement