Advertisement
Kojima0502

テキストファイル→テキストファイル 入出力

Sep 4th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void) {
  3.     char infile[40], outfile[40];
  4.     FILE *fin, *fout       ;
  5.     int c;
  6.    
  7.    
  8.     printf("Source file: ");
  9.     scanf("%39s", infile);
  10.     printf("Copy file: ");
  11.     scanf("%39s", outfile);
  12.    
  13.    
  14.     if ((fin=fopen(infile, "r")) == NULL) {
  15.         fprintf(stderr, "Source file open error.\n");
  16.         return 1;
  17.     }
  18.    
  19.     if ((fout=fopen(outfile, "w")) == NULL) {
  20.         fprintf(stderr, "Copy file open error.\n");
  21.         fclose(fin);
  22.         return 1;
  23.     }
  24.    
  25.    
  26.     while ((c=fgetc(fin))!=EOF) {
  27.         fputc(c, fout);        
  28.     }
  29.    
  30.    
  31.     fclose(fin);
  32.     fclose(fout);
  33.    
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement