本程序实现从文件中提取连续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. hdoj-1242-Rescue【广搜+优先队列】

    Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  2. ACdream原创群赛(13)のwuyiqi退役专场 C True love

    True love Time Limit: 4000/2000 MS (Java/Others)     Memory Limit:128000/64000 KB (Java/Others) Prob ...

  3. devres in linux driver

    写 driver 时, probe 中常常要为设备分配一些资源, 如 内存 / irq / gpio / iomap 等. 而在 probe 中失败时又要小心的释放掉这些资源. 底层驱动开发人员可能会 ...

  4. 下载Youku视频观看

    所需工具: 1.chorme内核浏览器,如Chorme.Firefox等等 2.vlc视频播放器 准备工作完成,开始工作 1.打开优酷的随便一个视频 2.按下F12选择Network(网络)选择Med ...

  5. enterText与typeText

    转自:http://www.cnblogs.com/hyddd/p/4126979.html 问题场景: Robotium.enterText输入数据后,点击"发送"按钮,多数情况 ...

  6. &lt;转&gt;bash: qmake: command not found...

    昨天发现qmake这个命令不能使用,查了一些资料,大部分都说是环境变量没有设置好: Qt默认安装是在 /opt/qt-xxxx/qt/bin 或者 /opt/qt-xxx/bin 下.实在不行就查找 ...

  7. Koa2学习(八)使用session

    Koa2学习(八)使用session koa2框架不提供session的处理方法,这里我们需要借助一个第三方中间件koa-session来处理session. 先安装插件: $ npm i koa-s ...

  8. npm学习笔记

    NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器下载并 ...

  9. order by 特殊排序技巧

    if object_id('tempdb..#temp') is not null drop table #temp ), col2 )) insert into #temp ' ' ' ' go - ...

  10. Lightoj 1006 Hex-a-bonacci

    Given a code (not optimized), and necessary inputs, you have to find the output of the code for the ...