Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.     // We have name of the source file
  8.     char *somename = "testfile";
  9.  
  10.     // Set file name as our name
  11.     const int SIZE_filename = strlen(somename) + 10;
  12.     char filename[SIZE_filename];
  13.     strcpy(filename, somename);
  14.  
  15.     // Set output name as file name with "_out" appended
  16.     const int SIZE_outfilename = strlen(filename) + 10;
  17.     char outfilename[SIZE_outfilename];
  18.     strcpy(outfilename, filename);
  19.     strcat(outfilename, "_out");
  20.    
  21.     FILE *file;
  22.     FILE *out;
  23.  
  24.     // Open files with their names
  25.     file = fopen(filename, "r");
  26.     out = fopen(outfilename, "w");
  27.  
  28.     // Read from source and write to the output file
  29.     char c;
  30.     while ((c = fgetc(file)) != EOF) {
  31.         fputc(c, out);
  32.     }
  33.  
  34.     fclose(file);
  35.     fclose(out);
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement