本程序实现从文件中提取连续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. Friefox清除旧的网页缓存

    Ctrl + F5 适用于调试网页编码时,不断以旧设置显示页面

  2. Android中的动画具体解释系列【2】——飞舞的蝴蝶

    这一篇来使用逐帧动画和补间动画来实现一个小样例,首先我们来看看Android中的补间动画. Android中使用Animation代表抽象的动画类,该类包含以下几个子类: AlphaAnimation ...

  3. the first week study

    1.In 1989, a man named Guido create "python" as a kind of computer languages. And now we u ...

  4. 树莓派的PWM脉宽调制功能介绍

    近期想用树莓派控制航模的电调,于是研究了下PWM.貌似控制电调比較麻烦,由于电调须要发送几个特定的信号启动,然后才干进入控制模式.今天先弄明确PWM,慢慢折腾.以下的程序亲測可用,我用的树莓派mode ...

  5. taskTracker和jobTracker 启动失败

    2011-01-05 12:44:42,144 ERROR org.apache.hadoop.mapred.TaskTracker: Can not start task tracker becau ...

  6. 60年代进程 80年代线程 IPC How the Java Virtual Machine (JVM) Works

    小结: 1. To facilitate communication between processes, most operating systems support Inter Process C ...

  7. Linux内核--基于Netfilter的内核级包过滤防火墙实现

    测试内核版本:Linux Kernel 2.6.35----Linux Kernel 3.2.1 原创作品,转载请标明http://blog.csdn.net/yming0221/article/de ...

  8. jquery中的工具函数 Utilities

    noConflict(deep) 释放$和Jquery的控制权 isFunction(obj) isArray(obj) isWindow(obj) isNumeric(obj) type(obj) ...

  9. USACO44 TimeTravel 时间旅行(链表)

    第一眼看到这题,woc,这不是主席树!?旁边HZ也表示同意,然后cGh队长就慢悠悠的过来:“想什么,USACO会有主席树!?” ↓打脸不解释,大家可以去%ta的博客(这样ta就不会D飞我了~)http ...

  10. Java 抽象类和接口的理解

    Java 抽象类和接口的理解 一.抽象类 为什么使用抽象类(个人理解): 面向对象的概念是,我们知道的所有的对象都是通过类来描绘的,如果类包含的信息不能描绘一个具体的对象,就需要抽象来解决了,意思是一 ...