#include <stdio.h>
#include <stdlib.h>

#define ACTION_OPEN_FILE       0
#define ACTION_WRITE_TO_STDOUT 1

typedef struct action_open_file
{
	int         type;
	const char *path;
	FILE       *file;
} action_open_file_t;

typedef struct action_write_to_stdout
{
	int         type;
	const char *string;
} action_write_to_stdout_t;

void execute_action_open_file(action_open_file_t *action)
{
	printf("the open file action is called.\n");
	
	action->file = !NULL; /* Типа открыл. */
}

void execute_action_write_to_stdout(action_write_to_stdout_t *action)
{
	printf("the write to stdout action is called.\n");
	
	printf("%s\n", action->string);
}

void execute_action(void *action)
{
	switch (*(int *)action)
	{
		case ACTION_OPEN_FILE:
			return execute_action_open_file(action);
			
		case ACTION_WRITE_TO_STDOUT:
			return execute_action_write_to_stdout(action);
	}
}

int main(void) 
{
	action_open_file_t action_1 =
	{
		.type = ACTION_OPEN_FILE,
		.path = "...",
		.file = NULL
	};
	
	action_write_to_stdout_t action_2 =
	{
		.type = ACTION_WRITE_TO_STDOUT,
		.string = "Hello World"
	};
	
	execute_action(&action_1); /* Вызывается функция execute_action_open_file. */
	execute_action(&action_2); /* Вызывается функция execute_action_write_to_stdout. */
	
	return EXIT_SUCCESS;
}
