发信人: kingfox() 
整理人: yangcs(2000-01-21 14:32:49), 站内信件
 | 
 
 
#include <string.h>
 #include <stdio.h>
 //-------------------------------------------------------------------- -------
 char FileName[256];
 char DestPath[256];
 char DestFile[256];
 char ListFile[256];
 
 int main()
 {
    FILE *ifp, *ofp, *fpList;
    long FragSize;
    long Number, Index;
    char Buf;
 
    do {
       printf( "Source file: " );
       scanf( "%s", FileName );
       ifp = fopen( FileName, "rb" );
       if ( ifp == NULL )
          printf( "Error file name: can not open dource file !\n" );
    } while( ifp == NULL );
 
    printf( "Destination path: " );
    scanf( "%s", DestPath );
    if ( DestPath[strlen(DestPath)-1] != '\\' )
       strcat( DestPath, "\\" );
    printf( "The size of file frag(BYTE): " );
    scanf( "%D", &FragSize );
 
    printf( "Fraging, please wait ...\n" );
    sprintf( ListFile, "%sfragment.lst", DestPath );
    fpList = fopen( ListFile, "w" );
    fprintf( fpList, "%s\n", FileName );
    for( Number = 0; ; Number ++ )
    {
       sprintf( DestFile, "frag%04d", Number );
       fprintf( fpList, "%s\n", DestFile );
       sprintf( DestFile, "%sfrag%04d", DestPath, Number );
       printf( "Creating file %s ...\n", DestFile );
       ofp = fopen( DestFile, "wb" );
       if ( ofp == NULL )
       {
          fclose( ifp );
          printf( "Error: can't create splited file !\n" );
 
          return -1;
       }
       for( Index = 0; Index < FragSize; Index ++ )
       {
          fread( &Buf, 1, 1, ifp );
          if ( feof( ifp ) )
          {
             fclose( ofp );
             fclose( ifp );
             printf( "Success to create frag file !\n" );
 
             return 0;
          }
          fwrite( &Buf, 1, 1, ofp );
       }
       fclose( ofp );
    }
 }
  -- ------------------------------------------------------------
 有缘则聚,缘尽则散,随缘而定,随遇而安。
 ------------------------------------------------------------
 欢迎光临“电子工程师园地”http://kingfox.163.net
  ※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.101.0.37]
  | 
 
 
 |