func-3.c - Same program - using a typedef to capture the function type. | Lecture 1 - slide 23 : 34 Program 3 |
#include <stdio.h> typedef void (*FUN)(char *, int); void fun1(char *s, int i){ printf("fun1: %s, %d\n", s, i); } void fun2(char *s, int i){ printf("fun2: %s, %d\n", s, i); } int main(void) { int cond; FUN f; printf("Enter condition (0, 1): "); scanf(" %d", &cond); if (cond) f = fun1; else f = fun2; f("AP", 8); return 0; }