/******************************************************************************
* 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. bugfree 安装配置(Ubuntu16.04 amd 64 Desktop)

    上面是我使用的版本! 1.首先搭建 xampp 下载XAMPP:https://www.apachefriends.org/download.html 注意:下载低版本的,不然之后会找不到mysql ...

  2. python3.7 安装pyopengl,环境搭建

    安装环境:win10 64位操作系统,python3.7 一.安装py库 需要用pip 安装 pip install PyOpenGL PyOpenGL_accelerate 可能会报错, 是因为没有 ...

  3. Springboot mybatis generate 自动生成实体类和Mapper

    https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...

  4. Excel表格的导入导出

    Excel文件的组成: 01.一个Excel文件由N个Sheet组成的 02.一个Sheet由N个Row组成 03.一个Row由N个Cell组成 需求: 把内存中的数据 写入到指定的excel表格中! ...

  5. myEclipse 下配置多个Tomcat

    1.进入perfomance 2. 进入server  右键点击configure server connector 3. 切换到 “Arguments” 面板,这里有 一个启动参数,就是修改一下路径 ...

  6. Codeforces 839B - Game of the Rows

    839B - Game of the Rows 思路:先放4个的,然后再放2个的,最后再放1个的. 代码: #include<bits/stdc++.h> using namespace ...

  7. 插件Vue.Draggable(5000🌟)

    安装资源库:从Vue资源:https://github.com/vuejs/awesome-vue下载 Libraries/UI Components/Form/Drag and Drop yarn ...

  8. Android之省市区三级联动

    最近项目要做一个电商APP,选择收货地址的三级联动滚动选择组件, 控件用起来非常简单 ,下面是它的运行效果: 布局 <LinearLayout xmlns:android="http: ...

  9. IE6不兼容postion:fixed已解决

    将要设置postion:fixed的元素的css中添加以下代码: //如果想要是头部悬停,则以下代码即可. .customService{        position: fixed;bottom: ...

  10. [NOI2018]你的名字(68pts)

    SAM真让人头秃. 题面 https://www.luogu.org/problemnew/show/P4770 首先考虑 l=1,r=∣S∣的做法 如果对于ION2018的子串不用判重的话,对ION ...