redir.c

来自「FIR2LIFT is a program to factor a wavele」· C语言 代码 · 共 73 行

C
73
字号
/*
FILE : REDIR.C

Implementation of a printf redirector.

(C) C. Valens

Created     : 21/09/1999
Last update : 23/09/1999
*/


#include <stdio.h>
#include <string.h>
#include <stdarg.h>


static const char *redir_default = "CON";
static FILE *outstream = NULL;


int redir_open(const char *what, const char *how)
{
  char str1[128], str2[10];

  if (what) {
    strcpy(str1,what);
  }
  else {
    strcpy(str1,redir_default);
  }

  if (how) {
    strcpy(str2,how);
  }
  else {
    strcpy(str2,"w");
  }

  if ((outstream=fopen(str1,str2))==NULL) {
    fprintf(stderr,"ERROR (redir_open) : could not open output stream.\n");
    return -1;
  }
  return 0;
}


int redir_close(void)
{
  fclose(outstream);
  return 0;
}


int redir_printf(const char *format, ...)
{
  /*
   * Declare other local variables here.
   */
  int count; 

  va_list ap;
  va_start(ap,format);

  count = vfprintf(outstream,format,ap);
  fflush(outstream);
  va_end(ap);

  return count;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?