C之函数指针
这方面的技能,在观察系统调用时,是很需要的。
但我不是很熟悉,另外,要再会函数指针数组的话,那就更强啦~~
按《HEAD FIRST C》作了个样例:
cat find.c
#include <stdio.h>
#include <string.h>
;
char *ADS[] = {
"William: SBM GSOH like sports, TV, dining",
"Matt: SWM NS likes art, movie, theater",
"Peter: SHN like out ,art",
"DWM: DS likes truncks, sports and bieber",
"Luis: SLM ND likes books, theater, art",
"Josh: SJM likes sports, movies and theater",
"Mike: DWM DS likes trucks, sports and bieber"
};
void find_raw() {
int i;
puts("Raw search results:");
puts("=================");
; i < NUM_ADS; i++) {
if (strstr(ADS[i], "sports" )
&& !strstr(ADS[i], "bieber")) {
printf("%s\n", ADS[i]);
}
}
puts("================");
}
int sports_no_bieber(char *s){
return strstr(s, "sports") && !strstr(s, "bieber");
}
int sports_or_workout(char *s){
return strstr(s, "sports") || strstr(s, "workout");
}
int theater_or_dining(char *s){
return strstr(s, "theater") || strstr(s, "dining");
}
void find(int (*match)(char*) ){
int i;
puts("Search results:");
puts("*******************");
; i < NUM_ADS; i++) {
if ((*match)(ADS[i])) {
printf("%s ;\n", ADS[i]);
}
if (!match(ADS[i])) {
printf("$$$$$$$$$$$$$\n");
}
}
puts("*************************");
}
int main() {
find_raw();
find(sports_or_workout);
find(&theater_or_dining);
;
}

C之函数指针的更多相关文章
- C++虚函数和函数指针一起使用
C++虚函数和函数指针一起使用,写起来有点麻烦. 下面贴出一份示例代码,可作参考.(需要支持C++11编译) #include <stdio.h> #include <list> ...
- 为什么 C++ 中成员函数指针是 16 字节?
当我们讨论指针时,通常假设它是一种可以用 void * 指针来表示的东西,在 x86_64 平台下是 8 个字节大小.例如,下面是来自 维基百科中关于 x86_64 的文章 的摘录: Pushes a ...
- C++函数指针总结
学习c++的过程中,指针是难点,熟悉了指针之后,还有一个让人很蛋疼的难点,那就是函数指针了.本博文详细介绍一下常见的各种坑爹的函数指针. 至于指针的详细学习,推荐这篇博文C++指针详解 与数据一样,函 ...
- C与指针(结构体指针,函数指针,数组指针,指针数组)定义与使用
类型 普通指针 指针数组(非指针类型) 数组指针 结构体指针 函数指针 二重指针 定义方式 int *p; int *p[5]; int (*p)[5]; int a[3][5]; struct{.. ...
- 结构体内嵌函数指针实现C语言面向对象
结构体内嵌函数指针 #include<stdio.h> void say(int age) { printf("我%d岁了\n",age); } struct stud ...
- 用typedef定义函数指针的问题
在学习windows API的时候,遇到下面这段代码 以前见过的typedef的用法都是给一个数据类型取一个别名 typedef oldTypeName newTypeName 这种给数据类型 ...
- 你必须知道的指针基础-7.void指针与函数指针
一.不能动的“地址”—void指针 1.1 void指针初探 void *表示一个“不知道类型”的指针,也就不知道从这个指针地址开始多少字节为一个数据.和用int表示指针异曲同工,只是更明确是“指针” ...
- objective-c中的@selector()和 c /c++的函数指针
先看tomcat里用到的代码: //然后开始动画 //把图片放到animationImages,接受数组参数 self.tom.animationImages = arrayImage; //设置时间 ...
- C++基础——函数指针 函数指针数组
==================================声明================================== 本文版权归作者所有. 本文原创,转载必须在正文中显要地注明 ...
- QT中使用函数指针
想仿命令行,所以定义了一个类,让一个String 对应一个 function,将两者输入list容器. 类中定义了 QString commandStr; void (MainWindow::*com ...
随机推荐
- 2015第23周四HTML特殊字符显示问题
1.项目中常采用EL表达式来输出后台内容,但测试发现它并不能完美处理要输出内容包含有<>或&等HTML特殊字符问题.先直接给出此问题JSTL的解决方案: 1.引入标签:<%@ ...
- poj3461 Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- Codeforces Round #272 (Div. 1) Problem C. Dreamoon and Strings
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Saruman's Army (POJ 3069)
直线上有N个点.点i的位置是Xi.从这N个点中选择若干个,给它们加上标记.对每一个点,其距离为R以内的区域里必须又带有标记的点(自己本身带有标记的点,可以认为与其距离为0的地方有一个带有标记的点).在 ...
- sicily 1155 Can I Post the letter
题意:判断有向图两点之间是否可通达! 解法:深搜或广搜(注意避免旧路重行) DFS: #include<iostream> #include<vector> #include& ...
- 漫谈MySQL primaryKey
主键没有着明确的概念定义,其是索引的一种,并且是唯一性索引的一种,且必须定义为“PRIMARY KEY”,是只可意会不可言传的东西.下面让我用通俗,甚至有些低俗的语言为您简单介绍一下MySQL的主键. ...
- python mysql curros.executemany 批量添加
#添加的表结构字段分辨是(id,title,summary,visits,accountName,grabTime) #其中id,是int自增主键,在添加操作的时候,不需要对id进行操作 conn = ...
- [RxJS] Reactive Programming - Sharing network requests with shareReplay()
Currently we show three users in the list, it actually do three time network request, we can verfiy ...
- grub2手动引导ubuntu
測试机OS为ubuntu 14.04.1 LTS x86_64 磁盘分区情况为: Filesystem 1K-blocks Used Available Use% Mounted on ...
- WebSphere之wasprofile.sh使用
概要文件(profile) 6.0版本以后才有profile,目的是将用户数据和was本身的文件分开,这样可以定义多个profile,每个profile相当于一个用户,相当于提供了多用户的支持. pr ...