File cutting

zhaozj2021-02-16  57

Below is the code for cutting the file and the merge file. It is some things I have written when I am used to familiarize my ability to operate with the file operation function. I have a good room, share with you, and listen to you. The program is debugged under UNIX_AIX.

/ ***************************

Mycut.c

File cutting program

Used to cut files into small files for 1024 bytes

*********************************** /

#include

#include

#include

#define size 1024

#define max 1048576 * 5

Main (int Argc, char ** argv)

{

Char buffer [size], c;

File * Source, * target;

Struct stat sbuf;

INT count = 0, n = 0;

Char flag = '0';

Char mycount [10];

CHAR Parts [10];

CHAR MYSIGN [20];

IF (argc! = 2)

{

FPrintf (stderr, "usage: source - file / n", * argv);

Exit (1);

}

IF ((Source = FOPEN (Argv [1], "R") == NULL)

{

PERROR (Argv [1]);

Exit (1);

}

Stat (Argv [1], & SBUF);

IF (SBUF.ST_SIZE> MAX)

{

Printf ("THE FILE IS TOO BIG / N");

exit (0);

}

/ * The number of blocks of the file * /

Count = SBUF.ST_SIZE / SIZE 1;

MEMSET (Mysign, 0, 10);

Printf ("% d / n", count);

/ * Record the number of files * /

Target = fopen ("thecount", "w");

Sprintf (mysign, "% d", count);

FPUTS (Mysign, Target);

Fclose (Target);

/ * Record file name * /

Target = fopen ("thefilename", "w");

FPUTS (Argv [1], Target;

Fclose (Target);

FOR (Flag = 0; flag

{

Sprintf (Mysign, "% D", FLAG);

Printf ("% s", mysign);

Target = fopen (mysign, "w");

n = fread (Buffer, Sizeof (Char), Size, Source

FWrite (Buffer, Sizeof (Char), N, Target);

Fclose (Target);

}

Fclose (Source);

exit (0);

}

/ ***************************

mycomb.c

File merger

Merged recovery for small files that will cut with the above program

*********************************** /

#include

#include

#include

#define size 1024

#define max 1048576 * 5

Main (int Argc, char ** argv) {

Char buffer [size], c;

File * Source, * target;

Struct stat sbuf;

INT count = 0, n = 0;

Char flag = '0';

Char mycount [10];

Char filename [20];

CHAR MYSIGN [10];

/ * Number of file blocks * /

IF ((Source = FOPEN ("Thecount", "R")) == NULL)

{

Printf ("Some Thing IS WRONG / N");

Exit (1);

}

MEMSET (MyCount, 0, 10);

FGETS (Mycount, 10, Source);

Fclose (Source);

REMOVE ("Thecount");

Count = ATOI (MyCount);

/ * Get file name information * /

IF ((Source = Fopen ("TheFileName", "R")) == NULL)

{

Printf ("Some Thing IS WRONG / N");

Exit (1);

}

MEMSET (FileName, 0, 20);

FGETS (Filename, 10, SOURCE);

Fclose (Source);

Remove ("thefilename");

Target = fopen (filename, "a");

MEMSET (Mysign, 0, 10);

/ * File merge * /

FOR (Flag = 0; flag

{

Sprintf (Mysign, "% D", FLAG);

Printf ("% s", mysign);

Source = fopen (mysign, "r");

n = fread (Buffer, Sizeof (Char), Size, Source

FWrite (Buffer, Sizeof (Char), N, Target);

Fclose (Source);

REMOVE (MYSIGN);

}

Fclose (Target);

exit (0);

}

转载请注明原文地址:https://www.9cbs.com/read-22332.html

New Post(0)