Advertisement
Kojima0502

バイナリファイル→バイナリファイル 入出力

Sep 4th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void) {
  3.     FILE *fin, *fout;
  4.     char infile[]="binary.raw";
  5.     char outfile[]="binary.raw";
  6.     double x;
  7.    
  8.    
  9.     if ((fin=fopen(infile, "rb"))==NULL) {
  10.         fprintf(stderr, "Data file open error.\n");
  11.         return 1;
  12.     }
  13.    
  14.     if ((fout=fopen(outfile, "wb"))==NULL) {
  15.         fprintf(stderr, "Result file open error.\n");
  16.         fclose(fin);
  17.         return 1;
  18.     }
  19.    
  20.    
  21.     while (fread(&x, sizeof(double), 1, fin) > 0) {
  22.         fprintf(fout, "%5.4f\n", x);
  23.     }
  24.    
  25.    
  26.     fclose(fin);
  27.     fclose(fout);
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement