C examples
最近在看David R. Hanson 的《C Interfaces and Implementations》,文中第一章提到了Literate Programming
作者举了一个例子:
功能:用于检测输入中相邻且相同的单词
#include<stdio.h>
#include<math.h>
#include<errno.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>int linenum;int getword(FILE *,char *,int);
void doubleword(char *,FILE *);int main(int argc,char *argv[]){int i;for(i=1; i<argc; i++){FILE *fp=fopen(argv[i],"r");if(fp==NULL){fprintf(stderr,"%s: can't open '%s'(%s)\n",argv[0],argv[i],strerror(errno));return EXIT_FAILURE;}else{doubleword(argv[i],fp);fclose(fp);}}if(argc==1) doubleword(NULL,stdin);return EXIT_SUCCESS;
}int getword(FILE *fp, char *buf, int size){int c;c=getc(fp);for(; c!=EOF && isspace(c); c=getc(fp)) //scan forword to a nonspace character or EOFif(c=='\n')linenum++;else{ //copy the word into buf[0……size-1]int i=0;for(: c!=EOF && !isspace(c); c=getc(fp))if(i<size-1) //size means the max length of any word int the textbuf[i++]=tolower(c);if(i<size)buf[i]='\0';}if(c!=EOF)ungetc(c,fp);return buf[0]!='\0';}void doubleword(char *name,FILE *fp){char prev[128],word[128];linenum=1;prev[0]='\0';while(getword(fp,word,sizeof(word))){if(isalpha(word[0])&& strcmp(prev,wortd)==0){if(name)printf("%s:",name);printf("%d:%s\n",linenum,word);}}
}
C examples相关推荐
- Tomcat V6 Examples移植到Apusic V5.1
目标:将Tomcat V6的的例子Examples移植到Apusic V5.1上 术语:Tomcat:只提供了WEB容器的开源服务器: Apusic:提供了完整的J2EE支持的商用服务器: %TOMC ...
- ChaLearn Gesture Challenge_2:examples体验
前言: 在上一篇博文ChaLearn Gesture Challenge_1:CGD数据库简单介绍中已经简单介绍过CGD2011数据库,了解到该数据库可以作为公开的数据库来测试在深度信息和RGB信息上 ...
- iPhone SDK Examples
2019独角兽企业重金招聘Python工程师标准>>> iPhone SDK Examples "Just show me how to do it!" 转载于: ...
- UserWarning: Label not :NUMBER: is present in all training examples
UserWarning: Label not :NUMBER: is present in all training examples 目录 UserWarning: Label not :NUMBE ...
- 如何编译ReactNative示例程序Examples
通过示例程序可以看到一些基本组件的使用,对于学习ReactNative是很有帮助的. 编译示例程序需要将整个项目导入到androidStudio中,androidStudio导入项目时选择react- ...
- How to use tcpdump with examples
为什么80%的码农都做不了架构师?>>> tcpdump 1.What is tcpdump? Tcpdump prints out a description ofthe c ...
- 用ORBSLAM2运行TUM Dataset数据集Monocular Examples
参照https://github.com/raulmur/ORB_SLAM2/blob/master/README.md 运行 4. Monocular Examples TUM Dataset 数据 ...
- 使用Android Studio build tensorflow/examples/android——直接用android studio即可
使用Android Studio 可以在Android Studio中直接打开tensorflow/examples/android,但是需要配置好你的gradle.sdk.ndk gradle必须要 ...
- Examples osgparticleshader例子学习
Examples osgparticleshader 粒子与shader的使用 参考文档 http://blog.csdn.net/csxiaoshui/article/details/234345 ...
- Computing image mean... ./examples/cifar10/create_cifar10.sh: 16: ./examples 怎么回事
Computing image mean... ./examples/cifar10/create_cifar10.sh: 16: ./examples 怎么回事 在运行caffe时出现下面的错误: ...
最新文章
- [置顶] 2014年八大最热门IT技能
- C++11 initializer_list 和 Range-based for loop 学习理解
- python 输出引号_python输出字符串单双引号如何选择
- web api 权限控制
- w3school---JQuery HTML
- bzoj 3111: [Zjoi2013]蚂蚁寻路(DP)
- OpenStack-Ocata版+CentOS7.6 云平台环境搭建 — 3.安装配置OpenStack认证服务(keystone)...
- 金山文字 职称计算机,计算机职称考试金山文字2005考试大纲
- python里的平方_python中的平方
- 他只靠写代码,登上了胡润富豪榜!
- winfrom给word加水印
- 使用set集合去除重复元素
- 游戏对战匹配逻辑小结
- 巴拿赫空间的基本性质
- C语言题目代码总结解析
- 关于JDBC我所想说的
- [SOA介绍]什么是SOA?
- Linux mysql数据库修改密码
- 在数据库如何对表进行查询
- 带你玩转Mysql高可用方案--PXC
热门文章
- Java学习总结:41(文件操作类:File)
- java 建树源码_Java实现的二叉树常用操作【前序建树,前中后递归非递归遍历及层序遍历】...
- 计算机rsnge指令,计算机二级office Excel 函数复习重点
- python中正确的表达式_python中如何正确使用正则表达式的详细模式(Verbose mode expression)...
- 【java】兴唐第十九节课(内部类)
- JS计算两个时间相差多久,相差年,月,日,小时,分钟
- PHP+MySql获取自动增长字段的新添加记录ID值
- 华为hybrid-vlan
- [企业化NET]Window Server 2008 R2[3]-SVN 服务端 和 客户端 基本使用
- 关于2012年度土建工程专业中级专业技术资格考试有关问题的通知