Skip to content

Commit cb4e421

Browse files
committed
Solution to task 4
1 parent 51569ab commit cb4e421

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
/**
5+
* error - prints error message and exits
6+
*
7+
* @err: error code
8+
*/
9+
void error(int err)
10+
{
11+
printf("Error\n");
12+
exit(err);
13+
}
14+
15+
/**
16+
* main - prints the opcodes of its own main function.
17+
*
18+
* @argc: number of arguments
19+
* @argv: array of arguments
20+
*
21+
* Return: 0
22+
*/
23+
int main(int argc, char *argv[])
24+
{
25+
int i, n;
26+
27+
if (argc != 2)
28+
error(1);
29+
30+
n = atoi(argv[1]);
31+
if (n < 0)
32+
error(2);
33+
34+
for (i = 0; i < n; i++)
35+
{
36+
printf("%02hhx", ((char *)main)[i]);
37+
if (i < n - 1)
38+
printf(" ");
39+
}
40+
printf("\n");
41+
return (0);
42+
}

0x0F-function_pointers/main

16.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)