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的更多相关文章
随机推荐
- Spring/Spring MVC/Spring Boot的区别
1.spring boot更简单,容易上手: 2.spring boot对第三方技术进行了很好的封装,提供了大量的第三方接口: 3.通过依赖配置,不需要XML等配置文件: 4.提供了安全性等特性. S ...
- visudo使用笔记
目录前言一.介绍二.配置文件简介三.实战配置 前言: su 的确为管理带来方便,通过切换到root下,能完成所有系统管理工具,只要把root的密码交给任何一个普通用户,他都能切换到root来完成 ...
- Codeforces 847H - Load Testing
847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- ehcache入门基础示例
一:目录 EhCache 简介 Hello World 示例 Spring 整合 二: 简介 1. 基本介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernat ...
- English trip -- VC(情景课)1 C What's your name?(review)
Xu言: 今天,阴差阳错又上了一次 VC 1 C的课,不过这次是小班的形式.这次课的教室叫 toronto [təˈrɒntəʊ] to ron to (多伦多(加拿大城市)) - -0我还 ...
- vue.js 过渡&动画
9-17 在add ,update, remove DOM时 提供多种方式的应用过度效果. 包括以下可选工具:(2大类,css和js) 在css过度和动画中自动应用class 配合使用第三方css动画 ...
- 3-30 flash(api),rescue_from(); logger简介
ActionDispatch::Flash < Objec pass temporary primitive-types (String, Array, Hash) between action ...
- Strip CodeForces - 487B (单调队列)
题面: Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Ale ...
- 『cs231n』RNN之理解LSTM网络
概述 LSTM是RNN的增强版,1.RNN能完成的工作LSTM也都能胜任且有更好的效果:2.LSTM解决了RNN梯度消失或爆炸的问题,进而可以具有比RNN更为长时的记忆能力.LSTM网络比较复杂,而恰 ...
- from * import *(ImportError: No module named *)为什么报错没有这个目录
先说下from * import * 的原理:比如有路径D:\fanbingbing\ai\wo.py这么一个文件,而现在你在D:\fanbingbing\buai\ni.py(别介意这么比喻..(⊙ ...