daily pastebin goal
94%
SHARE
TWEET

split.c

ibi May 13th, 2014 2,320 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // split 07/98 by bingen@lastresort.net
  3. //             for m.siefen
  4. //
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <io.h>
  8. #include <string.h>
  9. #include <dos.h>
  10. #include <direct.h>
  11.  
  12. #define TRUE   1
  13. #define FALSE  0
  14.  
  15. #define OUTFILE   "OUT"
  16.  
  17. void usage(void)
  18. {
  19.    printf(".compiled with watcom c/c++ 11.0. edited with zeus32 2.60.\n\n");
  20.    printf(".status:  freeware. use as often as you want.\n");
  21.    printf(".purpose: splitting large ascii-files.\n\n");
  22.    printf(".usage: SPLIT filename [splitsize]\n");
  23.    exit(-1);
  24. }
  25.  
  26. void main(int argc, char *argv[])
  27. {
  28.    FILE *stream;
  29.    FILE *stream2;
  30.    int   i, splitsize;
  31.    char  l=0;
  32.    char  str[255];
  33.    char  out[255];
  34.    char  in[255];
  35.  
  36.    printf("SPLIT v0.1 - (c)1998 by bingen@lastresort.net\n");
  37.    if (argc==1) usage();
  38.    if (argc>1) strcpy(in, argv[1]);
  39.    if (argc>2)
  40.       splitsize=atoi(argv[2]);
  41.    else
  42.       splitsize=100;
  43.  
  44.    printf("..splitting %s (%d lines each)\n",in,splitsize);
  45.    sprintf(out,"%s%d",OUTFILE,l);
  46.    stream=fopen(in,"r");
  47.    if(stream!=NULL)
  48.       {
  49.       while(!feof(stream))
  50.          {
  51.             stream2=fopen(out,"w");
  52.             if(stream2!=NULL)
  53.                {
  54.                for (i=1;i<=splitsize;i++)
  55.                   {
  56.                   if(fgets(str,255, stream)!=NULL)
  57.                      {
  58.                      fputs(str, stream2);
  59.                      printf("%s -> %d  \r", out, i);
  60.                      }
  61.                   else
  62.                      i=splitsize;
  63.                   }
  64.                fclose(stream2);
  65.                l++;
  66.                }
  67.           sprintf(out,"%s%d",OUTFILE,l);
  68.           printf("\n");
  69.          }
  70.    
  71.       fclose(stream);
  72.       }
  73.    else
  74.       printf("..file not found!\n");
  75.  
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top