/******************************************************************************
* 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的更多相关文章

随机推荐

  1. ubuntu server 16.04(amd 64) 配置网桥,多网卡使用激活

    安装了Ubuntu16.04的server版本,结果进入系统输入ifconfig后发现,只有一个网卡enp1s0,还有一个网络回路lo,ifconfig -a 发现其实一共有四个网卡,enp1s0,e ...

  2. python 基数排序

    def radix_sort(array): bucket, digit = [[]], 0 while len(bucket[0]) != len(array): bucket = [[], [], ...

  3. Python day15装饰器基本理论,以及结合全局变量模拟session

    装饰器(decorator):为其他函数添加附加功能 原则:1.不修改被修饰函数源代码 2.不修改被修饰函数的调用方式 装饰器=高阶函数+函数嵌套+闭包 import time def timmer( ...

  4. RabbitMQ入门_13_消息持久化

    参考资料:https://www.rabbitmq.com/tutorials/tutorial-two-java.html 默认情况下,队列中的消息是不持久化的.如果 RabbitMQ 崩溃,队列中 ...

  5. python数据持久存储-pickle模块

    pickle模块实现了基本的数据序列和反序列化.pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,通过pickle模块的反序列化操作,能够从文件中创建上一次程序保存的对象. 接 ...

  6. 554C - Kyoya and Colored Balls

    554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...

  7. Java 常用对象-基本类型的封装类

    2017-11-04 20:39:26 基本类型封装类:基本类型的封装类的好处是可以在对象中定义更多的功能方法操作该数据. 常用操作之一:用于基本数据类型与字符串的转换. 基本类型和包装类的对应: b ...

  8. [Java学习] Java方法重载

    在Java中,同一个类中的多个方法可以有相同的名字,只要它们的参数列表不同就可以,这被称为方法重载(method overloading). 参数列表又叫参数签名,包括参数的类型.参数的个数和参数的顺 ...

  9. 20170711筛选OutLook主题并转发

    Sub 筛选OutLook主题并转发() On Error Resume Next Dim OutApp As Application Set OutApp = Application Dim Out ...

  10. Confluence 6 从 Crowd 或 JIRA 应用中切换回使用内部用户管理

    如果你的 Confluence 站点当前使用的是 Crowd 或者 Jira 应用程序管理你的用的话,你可以按照下面的步骤切换使用回内部目录管理你的用户. 如果你的 Confluence 站点只有少量 ...