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的更多相关文章
随机推荐
- 理解Fragment的生命周期
与活动类似,Fragment也有自己的生命周期.理解Fragment的生命周期有助于在Fragment销毁时能恰当地保存其实例,然后在重新创建时能够将其恢复至之前的状态. 下面的“试一试”将研究Fra ...
- HTML表单格式化
HTML表单格式化 一.说明 用table布局 二.效果 三.代码 <!DOCTYPE html> <html> <head> <title>Form. ...
- php 邮件发送利器 PHPMailer
php 自带的邮件发送函数已经弱到不能用了. PHPMailer非常的强大. 绝对是php里必须使用的程序. 下载地址: https://github.com/Synchro/PHPMailer 只要 ...
- C#退出模式
1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit(); 强制所有消息中 ...
- 16 Managing Undo
16 Managing Undo 从Oracle11g开始,在默认安装中oracle会自动管理undo, 典型安装中不需要DBA介入配置,然而,如果选择了flash back特性,你就需要进行一些un ...
- protected 与 internal
protected:在当前类的“内部” 和 派生子类的“内部” 可访问(注意:实例对象不可访问 或者说 访问不到):如果静态,则在当前类内部和派生子类内部 具有“全局效果” internal:在 ...
- 自适应界面开发总结——WPF客户端开发
1.由于界面大小是变化的,所以必须有一个稳定不变的参考界面(即在一个标准的界面尺寸下进行WPF界面开发,比如:发票查验V3.0的美工设计尺寸——1024*740): PS:在WPF的用户控件Xam ...
- 3.4 复杂的x86指令举例
计算机组成 3 指令系统体系结构 3.4 复杂的x86指令举例 x86作为复杂指令系统的代表,自然会有不少相当复杂的指令.在这一节我们将会看到其中有代表性的一些例子. 关于复杂的x86指令,我们这里举 ...
- django-celery定时任务以及异步任务and服务器部署并且运行全部过程
Celery 应用Celery之前,我想大家都已经了解了,什么是Celery,Celery可以做什么,等等一些关于Celery的问题,在这里我就不一一解释了. 应用之前,要确保环境中添加了Celery ...
- Hibernate中的HQL的基本常用小例子,单表查询与多表查询
<span style="font-size:24px;color:#3366ff;">本文章实现HQL的以下功能:</span> /** * hql语法: ...