本程序实现从文件中提取连续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. Python第五讲

    一.冒泡算法 1.将两个变量的值互换 a1 = 123 a2 = 456 #要想将a1与a2的值进行位置互换需要借助一个中间变量(temp) temp = a1#将a1的值赋值给temp(temp=1 ...

  2. 关键路径(AOE)---《数据结构》严蔚敏

    // exam1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  3. Binder IPC的权限控制

    PS:个人理解:当进程1通过Binder调用组件2时,会将进程1的pid及uid赋给组件2,并检测进程1的pid及uid是否有权限调用组件2.而后组件2需要调用组件3,此时组件2保存的pid及uid为 ...

  4. awk基本使用方法简单介绍

    之前说过sed, 今天来说awk, 它也是一个文本处理器. 是linux下的一个命令, 比sed更强大. 搞linux开发, 尤其是后台开发, 这个命令差点儿必需要用到. awk这三个字母分别代表其三 ...

  5. poj 1840 哈希

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14093   Accepted: 6927 Description ...

  6. leveldb学习:DBimpl

    leveldb将数据库的有关操作都定义在了DB类,它负责整个系统功能组件的连接和调用.是整个系统的脊柱. level::DB是一个接口类,真正的实如今DBimpl类. 作者在文档impl.html中描 ...

  7. QC ALM 11创建域、项目和用户

    一旦HP-ALM安装,我们仅仅能继续创建域.项目和用户使用后的ALM工作.以下是步骤来创建项目.域和用户.       一.创建域 1.对于创建域,第一步是进入站点管理员页面.开展QC使用URL - ...

  8. 【iOS开发】-NSString的扩展使用

    第一:基本数据类型与字符串转换 //基本数据类型(int float,double char) 1)基本数据类型->NSString //1.int类型换换成字符串 int a = 88; NS ...

  9. Ios 项目从头开发 MVVM模式(三)

    1.话说,本来想做个聚合查询功能.可是我的重点想研究xmpp聊天功能.所以使用mvvm模式做了全然模式51job主界面的页面. 2.首先给大家看我执行起来的界面. 3.界面非常easy,做这个界面主要 ...

  10. 【bzoj3224】Tyvj 1728 普通平衡树

    交了一发pb_ds #include<ext/pb_ds/assoc_container.hpp> #include<algorithm> #include<iostre ...