#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  FILE *rh,*wh;
  int  i;
  char  *recordString; //"nnxxxxnn";
  unsigned char loadbuffer[256];
  
  if(argc!=4)
  {
    puts("bincut inputfile outputfile record");
    return(0);
  }
  
  recordString=argv[3];
  
  //puts(argv[3]);
  
  rh = fopen(argv[1],"rb");
  if(rh==NULL)
  {
    puts("cant open input file");
    return(-1);
  }
  
  wh = fopen(argv[2],"wb");
  if(wh==NULL)
  {
    puts("cant create output file");
    fclose(rh);
    return(-1);
  }
  
  while(fread(loadbuffer,strlen(recordString),1,rh))
  {
    for(i=0;i<strlen(recordString);i++)
    {
          if(recordString[i]=='x')
          {
                   // printf("%4.4x ",loadbuffer[i]);
                    fwrite(&loadbuffer[i],1,1,wh);
          }  
    }
    //puts("");
  }
  
    
  
  fclose(rh);
  fclose(wh);
    
  //system("PAUSE");	
  return 0;
}
