字符定位
#include<stdio.h>
char *match(char *s, char ch);
int main(void){
char ch, str[80],*p = NULL;
scanf("%s", str);
getchar();
ch = getchar();
if((p = match(str, ch)) != NULL){
printf("%s\n", p);
}else{
printf("Not Found\n");
}
return 0;
}
char *match(char *s, char ch){
while(*s != '\0'){
if(*s == ch){
return (s);
}else{
s++;
}
}
return (NULL);//在s里没有找到返回空指针
}
输入:
happypy y
输出:
ypy
函数指针定义如:int (*funptr) (int , int);
假设函数fun(x, y)已定义,它有两个整型参数且返回一个整形量,则
funptr = fun;
将fun( )的入口地址赋给funptr ,funptr就指向fun( ).
调用函数的两种方法:
fun(3, 5);
(*funptr)(3, 5);
cal(f, a, b)用梯形公式求函数f(x)在[a, b]上的数值积分
这里写代码片