#cat para_callback.h
#ifndef PARA_CALLBACK_H
#define PARA_CALLBACK_H

typedef void (*callback_t) (void *);

extern void repeat_three_times (callback_t,void *);
#cat para_callback.c
#include "para_callback.h"

void repeat_three_times(callback_t f, void *para){
	f(para);
	f(para);
	f(para);
}

#cat main.c
#include <stdio.h>
#include "para_callback.h"

void say_hello(void *str){
	printf("Hello %s\n",(const char*)str);
}

void count_numbers(void *num){
	int i;
	for(i=1; i< (int)num; i++){
		printf("%d ", i);
		putchar('\n');
	}
}

int main(void){
	repeat_three_times(say_hello,"muahao");
	repeat_three_times(count_numbers,(void*)4);
	return 0;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2022-03-03
  • 2022-12-23
  • 2022-01-02
  • 2022-01-09
相关资源
相似解决方案