c语言之IO使用文件分割
来源:互联网 发布:2k18艾佛森捏脸数据 编辑:程序博客网 时间:2024/06/05 04:26
#include <stdio.h>#include <math.h> // ceil()#include <stdlib.h> // exit()//cl filesplit.cint main(int argc, char *argv[]) { char part_filename[200]; FILE *ptr_source, *ptr_part; size_t parts, i; unsigned long int part_size, written_bytes; int byte; if (argc != 3) { printf("Usage: %s <maximum part_size in MB> <file to split>\n", argv[0]); exit(1); } if ((ptr_source = fopen(argv[2], "rb")) == NULL) { perror("Could not open file to split"); exit(1); } fseek(ptr_source, 0, SEEK_END); part_size = atol(argv[1]) * 1024 * 1024; if (part_size == 0) { printf("Invalid part size: %s\n", argv[1]); exit(1); } parts = (size_t) ceil((double) ftell(ptr_source) / part_size); rewind(ptr_source); printf("File will be split into %u parts.\n", parts); for (i = 0; i < parts; i++) { printf("\nWriting part%02d... ", i); sprintf(part_filename, "%s.part%02d", argv[2], i); if ((ptr_part = fopen(part_filename, "wb")) == NULL) { perror("Could not open part for writing"); exit(1); } for (written_bytes = 0; written_bytes < part_size && (byte = fgetc(ptr_source)) != EOF; written_bytes++) { fputc(byte, ptr_part); } printf("(%lu bytes)", written_bytes); fclose(ptr_part); } printf("\n\nDone!\n"); fclose(ptr_source); return 0;}
0 0
- c语言之IO使用文件分割
- C语言之文件IO
- c语言之分割与合并文件
- c语言-文件io
- C语言 文件IO
- C语言学习笔记之文件的分割与合并
- C语言之分割字符串
- JAVA之IO技术 分割文件
- linux c语言学习笔记之文件IO
- C语言文件IO操作
- C语言自制文件分割器(简单)
- C 语言使用特定字符分割字符串
- C语言:使用strtok()函数分割字符串
- APUE笔记—C语言标准IO库之文件IO
- c语言之头文件的使用
- C++IO之文件操作
- 使用 IO 流,分割/合并 处理大文件
- 【C语言】IO--文件操作要点
- 装箱子
- 利用事件分发机制解决ScrollView嵌套ListView滑动冲突
- Oracle 查询优化的基本准则详解
- Eclipse集成Tomcat 报错Tomcat 7.x JDK name
- 优先级队列:PriorityQueue
- c语言之IO使用文件分割
- HTML5之canvas5
- 针对线程学习过程中遇到的问题或者是学习经验笔记
- 原创XListView
- SDOS_SdoInfoInd
- CocoaPods安装及使用
- hdu_5293_Tree chain problem(DFS序+树形DP+LCA)
- 【城会玩】hrbust 1341Who will be punished【思维】
- 一个有序的二维数组,自上而下,自左至右都是升序,判断输入的整数是否在数组中