C++ Creating and writing files

Creating and writing files

#include <dir.h>
#include "cxlvid.h"
#include "cxlwin.h"

extern int num_chan;

int num_files;

char search[50][70];

int files_in_out (int flag)
{
  int i, w_col, done;
  struct ffblk ffblk;
  char file_name[100];

  if (flag) {
      // ‚µ®¤¿¹¨
      sprintf (file_name, "c:\\work\\?*.%1d", num_chan);
      w_col= 67;
     }
     else {
           // ˆ§µ¤¿¹¨
           sprintf (file_name, "c:\\work\\?*.g*");
           w_col= 2;
          }

  for (i=0; i<50; i++) search[0][0]='\x0';
  i=0;

  // Are there any  opened gramas?
  file_name[8] = 'G';
  done = findfirst (file_name, &ffblk, 0);
  while (!done) {
	 if (i==_winfo.maxfiles) break;
	 strncpy (search[i], ffblk.ff_name, sizeof(ffblk.ff_name));
	 i++;
	 done=findnext(&ffblk);
	}

  // Are there any digital gramas?
  file_name[8] = 'C';
  done = findfirst (file_name, &ffblk, 0);
  while (!done) {
	 if (i==_winfo.maxfiles) break;
	 strcpy (search[i], ffblk.ff_name);
	 i++;
	 done = findnext (&ffblk);
	}

// Are there any coded gramas?
  file_name[8] = 'S';
  done = findfirst (file_name, &ffblk, 0);
  while (!done) {
	 if (i==_winfo.maxfiles) break;
	 strcpy (search[i], ffblk.ff_name);
	 i++;
	 done = findnext (&ffblk);
	}


  strcpy (search[i], "");
  num_files=i;
  {

   int attr, a;

   a = wattr;
   if (_vinfo.mono) attr = LGREY|_BLACK;
     else attr = WHITE|_CYAN;
   for (i=0; i< num_files && i < 6; i++)
	prints (18+i,  w_col, attr, search[i]);
   for (i=num_files; i< 6; i++) prints (18+i, w_col, attr, "          ");
   wattr = a;
  }
  return (0);
}


void gramas (void)
{
  files_in_out (0);
  files_in_out (1);
}