Created
November 4, 2022 16:28
-
-
Save alex-robert-fr/8789a443e36fb4c0c9d0de609bf34cd3 to your computer and use it in GitHub Desktop.
Singleton in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Header | |
#define MAX_FLAG 0xe | |
typedef struct s_printf t_printf; | |
struct s_printf | |
{ | |
const char flag; | |
int (*cb)(const char *, int); | |
}; | |
const t_printf *get_flag(const char flag); | |
// Source | |
const t_printf *get_flag(const char flag) | |
{ | |
static const t_printf f[MAX_FLAG] = { | |
{ 's', ft_putstr_fd }, | |
{ 'c', ft_putchar_fd }, | |
}; | |
int i; | |
i = 0; | |
while (i < MAX_FLAG) | |
{ | |
if (f[i].flag == flag) | |
return (&f[i]); | |
i++; | |
} | |
return (NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment