removeLineEndSpace
/******************************************************************************
* removeLineEndSpace
* 声明:
* 该程序是之前alignBySpace的逆向补充程序,去掉行尾的空格。
*
* 2015-8-11 阵雨 深圳 南山平山村 曾剑锋
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h> int main ( int argc, char ** argv ) { int ret = ;
char *tempFile = "generateFile.txt";
char *readBuffer = NULL;
size_t bufferSize = ;
int readBufferIndex = ; if ( argc != ) {
printf ( "USAGE:\n" );
printf ( " removeLineEndSpace <file>.\n" );
return -;
} FILE *readfile = fopen ( argv[], "r" ); // only read
FILE *writefile = fopen ( tempFile, "w" ); // only write /**
* man datasheet:
* If *lineptr is NULL, then getline() will allocate a buffer for storing the line,
* which should be freed by the user program. (In this case, the value in *n is ignored.)
*/
while ( ( ret = getline( &readBuffer, &bufferSize, readfile ) ) != - ) { readBufferIndex = ret - ; // index for real position while ( ( readBuffer [ readBufferIndex ] == ' ' ) || // del ' ', '\t', '\n' character
( readBuffer [ readBufferIndex ] == '\n' ) || ( readBuffer [ readBufferIndex ] == '\t' ) )
readBuffer [ readBufferIndex-- ] = '\0'; readBuffer [ readBufferIndex + ] = '\n'; fputs ( readBuffer, writefile ); // write to file bzero ( readBuffer, ret ); // clean buffer
} free ( readBuffer ); // referrence getline() fclose ( readfile );
fclose ( writefile ); remove ( argv[] ); // delete source file
rename ( tempFile, argv[] ); // tempfile rename to source file
}
removeLineEndSpace的更多相关文章
随机推荐
- Java中的hashcode方法
一.hashCode方法的作用 对于包含容器类型的程序设计语言来说,基本上都会涉及到hashCode.在Java中也一样,hashCode方法的主要作用是为了配合基于散列的集合一起正常运行,这样的散列 ...
- angular5 ng-bootstrap和ngx-bootstrap区别
https://angular.cn/resources ngx-bootstrap 安装: npm install ngx-bootstrap --save 再引入css <link href ...
- Java的JDK和JRE
Java的JDK和JRE 1.计算机交互方式 图形化界面(Graphical User Interface GUI) 命令行方式(Command Line Interface CLI) 2.Java语 ...
- linux使用flock文件锁
使用linux flock 文件锁实现任务锁定,解决冲突 格式: flock [-sxun][-w #] fd# flock [-sxon][-w #] file [-c] command flock ...
- Up and Down the Tree CodeForces - 1065F (树形dp)
链接 题目大意:给定$n$结点树, 假设当前在结点$v$, 有两种操作 $(1)$移动到$v$的子树内任意一个叶子上 $(2)$若$v$为叶子, 可以移动到距离$v$不超过$k$的祖先上 初始在结点$ ...
- 『科学计算_理论』优化算法:梯度下降法&牛顿法
梯度下降法 梯度下降法用来求解目标函数的极值.这个极值是给定模型给定数据之后在参数空间中搜索找到的.迭代过程为: 可以看出,梯度下降法更新参数的方式为目标函数在当前参数取值下的梯度值,前面再加上一个步 ...
- node搭建本地服务器
随着前端不断发展,node基本已经成为必备,在调试的时候经常需要服务器,在之前的做法通常是去下载一个phpstudy 或者 xampp等启动一个服务,作为一个前端人虽然可以借助各种工具,但是怎么能不懂 ...
- Oracle11g温习-第八章:归档日志
2013年4月27日 星期六 10:36 1.归档和非归档的区别 1) 归档会在日志切换时,备份历史日志,用于OLTP(在线事务处理系统),可以进行冷备份和热备份,可以实现数据库完全恢复.不完全恢复 ...
- mahout推荐系统
本章包含以下内容: 首先看一下实战中的推荐系统 推荐引擎的精度评价 评价一个引擎的准确率和召回率 在真实数据集:GroupLens 上评价推荐系统 我们每天都会对喜欢的.不喜欢的.甚至不关心的事情有很 ...
- Dos命令下目录操作
Dos命令下目录操作 1.cd 操作 显示当前目录名或改变当前目录 cd [盘符][路径] 进入指定盘符下的目录 cd [..] ...