0x0F. C Function pointers Task 1 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
Write a function that executes a function given as a parameter on each element of an array.
- Prototype:
void array_iterator(int *array, size_t size, void (*action)(int));
- where
size
is the size of the array - and
action
is a pointer to the function you need to use
julien@ubuntu:~/0x0e. Function pointers$ cat 1-main.c
#include <stdio.h>
#include "function_pointers.h"
/**
* print_elem - prints an integer
* @elem: the integer to print
*
* Return: Nothing.
*/
void print_elem(int elem)
{
printf("%d\n", elem);
}
/**
* print_elem_hex - prints an integer, in hexadecimal
* @elem: the integer to print
*
* Return: Nothing.
*/
void print_elem_hex(int elem)
{
printf("0x%x\n", elem);
}
/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
int array[5] = {0, 98, 402, 1024, 4096};
array_iterator(array, 5, &print_elem);
array_iterator(array, 5, &print_elem_hex);
return (0);
}
julien@ubuntu:~/0x0e. Function pointers$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 1-main.c 1-array_iterator.c -o b
julien@ubuntu:~/0x0e. Function pointers$ ./b
0
98
402
1024
4096
0x0
0x62
0x192
0x400
0x1000
julien@ubuntu:~//0x0e. Function pointers$
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x0F-function_pointers
- File: 1-array_iterator.c