空格填充器(alignBySpace)
/*******************************************************************
* 空格填充器(alignBySpace)
* 声明:
* 1. 软件主要是在不改变文本文件内容情况下,自动填充空格一定数量的
* 空格,达到空格右对齐的功能;
* 2. 本软件主要是节省个人的代码跟踪文档打空格的时间;
*
* 2015-8-3 晴 深圳 南山平山村 曾剑锋
******************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h> int main ( int argc, char ** argv ) { int ret = ;
int column = ;
char *tempFile = "generateFile.txt";
char *readBuffer = NULL;
size_t bufferSize = ;
int readBufferIndex = ;
int writeBufferIndex = ;
char writeBuffer[bufferSize]; if ( ( argc < ) || ( argc > ) ) {
printf ( "USAGE:\n" );
printf ( " alignBySpace <file> [column].\n" );
return -;
} if ( argc == ) {
printf ( "\nUse default columns: 80. \n\n" );
column = ;
} else
column = atoi ( argv[] ); 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 = ;
writeBufferIndex = ; while ( readBufferIndex < ret ) {
if ( readBuffer [ readBufferIndex ] != '\t' ) // kick out '\t'
writeBuffer [ writeBufferIndex++ ] = readBuffer [ readBufferIndex++ ];
else {
memset ( writeBuffer + writeBufferIndex, ' ', ); // every tab key was 4 space
writeBufferIndex += ;
readBufferIndex++;
}
} writeBufferIndex--; // back to real index if ( ( column - writeBufferIndex ) > ) { // may be real column longer than we set
// '\n' at end of a line, need to kick it out
memset ( writeBuffer + writeBufferIndex, ' ', column - writeBufferIndex );
writeBuffer [ column ] = '\n'; // for end of a line
writeBuffer [ column + ] = '\0'; // for end of a string
} else
writeBuffer [ writeBufferIndex + ] = '\0'; // make sure end of a string fputs ( writeBuffer, writefile ); // write to file bzero ( readBuffer, bufferSize ); // clean buffer
bzero ( writeBuffer, bufferSize ); } free ( readBuffer ); // referrence getline() fclose ( readfile );
fclose ( writefile ); remove ( argv[] ); // delete source file
rename ( tempFile, argv[] ); // tempfile rename to source file
}
空格填充器(alignBySpace)的更多相关文章
- laravel 填充器Seed
我们在进行多人开发时,发现运行php artisan db:seed --class=填充器名称 发现有报错 Exception trace: 1 ReflectionClass::__constru ...
- Android数据填充器LayoutInflater
LayoutInflater类在应用程序中比较实用,可以叫布局填充器,也可以成为打气筒,意思就是将布局文件填充到自己想要的位置,LayoutInflater是用来找res/layout/下的xml布局 ...
- Android LayoutInflater布局填充器
Android LayoutInflater布局填充器 把一份xml布局文件转为View对象,这就是layoutinflater的作用. 对于一个没有被载入或者想要动态载入的界面,都需要使用Layou ...
- Android LayoutInflater(布局填充器)
先来看一下LayoutInflater的基本用法吧,它的用法非常简单,首先需要获取到LayoutInflater的实例,有两种方法可以获取到,第一种写法如下: LayoutInflater layou ...
- SQL Server 2008 R2【SET ANSI_PADDING填充属性】插入一条数据后,为何每一列都默认的在字符后多了几个空格
当加入空格后查出 解决: 导致出现这样的现象的原因就是SET ANSI_PADDING选项. 这个选项只在数据表的字符串字段被更新或者新的数据行插入到表中的时候作用.它控制着SQL Server在遇到 ...
- lucene分词器与搜索
一.分词器 lucene针对不同的语言和虚伪提供了许多分词器,我们可以针对应用的不同的需求使用不同的分词器进行分词.我们需要注意的是在创建索引时使用的分词器与搜索时使用的分词器要保持一致.否则搜索的结 ...
- laravel 数据填充
编写填充器 php artisan make:seeder UserTableSeeder 修改Laravel安装时自带的DatabaseSeeder类,添加一个数据库插入语句到run方法: < ...
- Laravel 5.2 教程 - 数据填充
一.简介 Laravel提供的填充类(seed),可以让大家很容易的实现填充测试数据到数据库.所有的填充类都位于database/seeds目录.填充类的类名完全由你自定义,但最好还是遵循一定的规则, ...
- Laravel 5.2数据库--填充数据
1.简介 Laravel 包含了一个简单方法来填充数据库——使用填充类和测试数据.所有的填充类都位于database/seeds目录.填充类的类名完全由你自定义,但最好还是遵循一定的规则,比如可读性, ...
随机推荐
- ubuntu server 16.04(amd 64) 配置网桥,多网卡使用激活
安装了Ubuntu16.04的server版本,结果进入系统输入ifconfig后发现,只有一个网卡enp1s0,还有一个网络回路lo,ifconfig -a 发现其实一共有四个网卡,enp1s0,e ...
- git 生成 公钥
生成公钥 ssh-keygen -t rsa -C "your email" 查看公钥 cat ~/.ssh/id_rsa.pub
- [ios]关于ios开发图片尺寸的建议
1.以后的应用程序,都使用AutoLayout, 不要再用绝对定位. 2.使用类似网页的方式来设计界面. 3.设计师好,程序员也好,尽量使用点这个单位进行思考,而不要使用像素.比如,你需要做44 x ...
- 【Golang】字符串首字母大小写转化
写在前面 在自动化过程中,我们用得最多的可能就是字符串的处理,熟悉Python的都知道在Python中要让一个字符串的首字母大写直接用capitalize就可以了,但是同样的事情在Golang中没有这 ...
- Servlet之javax.servlet包
链接 : http://blog.sina.com.cn/s/blog_5d4214c70102wnf1.html
- Python -- Json 数据编码及解析
Python -- Json 数据编码及解析 Json 简单介绍 JSON: JavaScript Object Notation(JavaScript 对象表示法) JSON 是存储和交换文本 ...
- Python 爬虫-正则表达式(补)
2017-08-08 18:37:29 一.Python中正则表达式使用原生字符串的几点说明 原生字符串和普通字符串的不同 相较于普通字符串,原生字符串中的\就是反斜杠,并不表达转义.不过,字符串转成 ...
- [Spring Boot] 使用多个Servlet
当使用Spring boot的嵌入式servlet容器时,可以通过Spring bean或扫描Servlet组件的方式注册Servlet.Filter和Servlet规范的所有监听器(例如HttpSe ...
- JdbcTemplate.queryForObject
} catch (EmptyResultDataAccessException e) { log.info(">>>检测到有无记录>>>>" ...
- javascript开发HTML5游戏--斗地主(单机模式part1)
最近学习使用了一款HTML5游戏引擎(青瓷引擎),并用它尝试做了一个斗地主的游戏,简单实现了单机对战和网络对战,代码可已放到github上,在此谈谈自己如何通过引擎来开发这款游戏的. 客户端代码 ...