Write a function that prints a name.
- Prototype:
void print_name(char *name, void (*f)(char *));
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
Write a function that searches for an integer.
- Prototype:
int int_index(int *array, int size, int (*cmp)(int));
- where
size
is the number of elements in the arrayarray
cmp
is a pointer to the function to be used to compare valuesint_index
returns the index of the first element for which thecmp
function does not return0
- If no element matches, return
-1
- If size <=
0
, return-1
3. A goal is not always meant to be reached, it often serves simply as something to aim at mandatory
Write a program that performs simple operations.
- You are allowed to use the standard library
- Usage:
calc num1 operator num2
- The program prints the result of the operation, followed by a new line
num1
,num2
are integers. Use theatoi
function to convert them toint
operator
is one of the following:+
: addition-
: subtraction*
: multiplication/
: division%
: modulo
- You can assume that the result of all operations can be stored in an
int
- if the number of arguments is wrong, print
Error
, followed by a new line, and exit with the status98
- if the
operator
is none of the above, printError
, followed by a new line, and exit with the status99
- if the user tries to divide (
/
or%
) by0
, printError
, followed by a new line, and exit with the status100
This task requires that you create four different files.
3-calc.h
This file should contain all the function prototypes and data structures used by the program. You can use this structure:
4. Most hackers are young because young people tend to be adaptable. As long as you remain adaptable, you can always be a good hacker #advanced
Write a program that prints the opcodes of its own main function.
- Usage:
./main number_of_bytes
- Output format:
- the opcodes should be printed in hexadecimal, lowercase
- each opcode is two char long
- listing ends with a new line
- see example
- You are allowed to use
printf
andatoi
- You have to use
atoi
to convert the argument to anint
- If the number of argument is not the correct one, print
Error
, followed by a new line, and exit with the status1
- If the number of bytes is negative, print
Error
, followed by a new line, and exit with the status2
- You do not have to compile with any flags
Note: if you want to translate your opcodes to assembly instructions, you can use, for instance udcli.