本程序实现从文件中提取连续4个以上的可打印字符。模仿linux中string命令

#include <stdio.h>
#include<stdlib.h>
#include <ctype.h>
#define BUFSIZE 4096
void strings(FILE*fp);
int main(int argc,char*argv[])
{
FILE* fp;
if(argc==1)
{
fp=stdin;
strings(fp);
}
else
{
int i=1;
for(;i<argc;i++)
{
if((fp=fopen(argv[i],"r"))==NULL)
{
fprintf(stderr,"open %s error.\n",argv[i]);
continue;
}
strings(fp);
close(fp);
}
}
return 0;
} void strings(FILE*fp)
{
int c;
char buf[BUFSIZE];
int last = 0;
while(1)
{
c = getc(fp);
if ((isprint(c)||c=='\t')&&last < BUFSIZE-1)//标准strings命令也接受'\t'
buf[last++] = c;
else
{
if (last >= 4)
{
buf[last] = '\0';
printf("%s\n", buf);
}
last = 0;
}
if (c == EOF) break;
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

strings命令的实现 2014-06-02 00:17 355人阅读 评论(0) 收藏的更多相关文章

  1. tac命令的实现 分类: linux 2014-06-02 00:08 344人阅读 评论(0) 收藏

    此程序实现简化的linux中的tac命令.即对文件按行倒序输出. 首先将文件指针置于文件尾,从后向前移动指针, 将两个换行符'\n'间的内容作为一行输出. #include<stdio.h> ...

  2. Codeforces801B Valued Keys 2017-04-19 00:21 136人阅读 评论(0) 收藏

    B. Valued Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  3. How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏

    1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...

  4. Work around by " Due to heavy load, the latest workflow operation has been queued. " 分类: Sharepoint 2015-07-08 00:19 3人阅读 评论(0) 收藏

    I hope most of the users and developers might have come across above note and worried about it. Ther ...

  5. C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏

    const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...

  6. 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏

    1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...

  7. 浅谈new operator、operator new和placement new 分类: C/C++ 2015-05-05 00:19 41人阅读 评论(0) 收藏

    浅谈new operator.operator new和placement new C++中使用new来产生一个存在于heap(堆)上对象时,实际上是调用了operator new函数和placeme ...

  8. short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...

  9. NYOJ-733 万圣节派对 AC 分类: NYOJ 2014-01-02 00:41 303人阅读 评论(0) 收藏

    #include <stdio.h> #include <math.h> int main() { int t, a, b, i, j, n; scanf("%d&q ...

随机推荐

  1. java quartz的使用,做时间轮询调用 CronTrigger

    import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionExceptio ...

  2. App中显示html网页

    在现在的移动开发中,越来越多的web元素增加到了app里面,hybrid app可以综合native app 和 web app的长处,可以通过webView实现 htmllayout.xml: &l ...

  3. Angular2.x-主/细节组件

    此刻,HeroesComponent显示heroes列表和所选heroes的详细信息. 随着应用程序的增长保持一个组件中的所有功能将不可维护.您需要将大型组件分成更小的子组件,每个组件都专注于特定的任 ...

  4. CSDN-markdown基本的语法说明

    文件夹 概述 简介Markdown CSDN Markdown的功能支持 标题 Setext形式 atx形式 区块引用 分隔线 强调 列表 无序列表 有序列表 注意事项 链接 自己主动链接 普通文本链 ...

  5. vue 手风琴组件

    1.创建组件 SqueezeBox.vue <!-- 手风琴(三级折叠列表) 组件 --> <template> <div class="header" ...

  6. Codeforces Round #221 (Div. 2) D

    有点郁闷的题目,给了2000ms,可是n,m的范围已经是5000了.5000 * 5000一般在别的OJ已经是超了2000ms,一開始不敢敲.看了下别人有n*m的潜逃循环,原来CF的机子如此的强大,一 ...

  7. 解决echart在IE中使用时,在div中加入postion后图表不显示问题

    <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="height:400px;width:1 ...

  8. [10.27_P3] 简单题 (脑洞)

    Description dzy 手上有一张n 个点m 条边的联通无向图,仙人掌是一张每条边最多在一个简单环内的联通无向图.他想求这个无向图的生成仙人掌中最多有多少条边. 但是dzy 觉得这个问题太简单 ...

  9. Java 内存管理、JVM 工作原理与 Java 运行时系统

    Java 虚拟机规范中说明:所有的对象实例(all class instances)以及数组都要在堆上分配: the heap is the runtime data area from which ...

  10. uwsgi 配置 初试

    /************************************************************************************** * uwsgi 配置 初 ...