Exer4.6.c(undone)

//程序可以正常运行,但file.nohole始终没有东西写进去,为什么?

 
#include "apue.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
 
int main(int argc, char *argv[]){
  FILE *fp1, *fp2; 
  char chr;
  int fd, count = 0;
 
  if(argc != 3)
    err_quit("Usage: %s <src> <dest>", argv[0]);
 
  if((fp1 = fopen(argv[1], "r")) == NULL)
    err_sys("fopen %s error", argv[1]);
  if((fd = open(argv[2], O_CREAT|O_EXCL|O_TRUNC, S_IRWXU|S_IRGRP)) < 0)
    err_sys("create %s error", argv[2]);
  if((fp2 = fdopen(fd, "rw")) == NULL)
    err_sys("transfer from filedes to file stream error");
  while((chr = getc(fp1)) != EOF){
    count++;
    if(!chr){
      continue;
    }
 
    putc(chr, stdout);
    printf("\ncount: %d\n", count);   
    putc(chr, fp2);
  }
  //  putc(EOF, stdout); // '?' printed
  putc(EOF, fp2);
  fflush(fp2);
  if(fclose(fp2) == EOF)
    err_sys("fclose fp2 error");
  exit(0);
}
原文地址:https://www.cnblogs.com/beanmoon/p/2732042.html