We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fb37e52 commit 6c14bb3Copy full SHA for 6c14bb3
0x0F-function_pointers/100-main_opcodes.c
@@ -0,0 +1,39 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+
4
+/**
5
+ * main - prints the opcodes of its own main function.
6
+ *
7
+ * @argc: num of args.
8
+ * @argv: arguments' values
9
10
+ * Return: always success (0), (1) otherwise.
11
+ */
12
+int main(int argc, char **argv)
13
+{
14
+ int nBytes, index;
15
+ char *xmain = (char *)main;
16
17
+ if (argc != 2)
18
+ {
19
+ printf("Error\n");
20
+ exit(1);
21
+ }
22
23
+ nBytes = atoi(argv[1]);
24
+ if (nBytes < 0)
25
26
27
+ exit(2);
28
29
30
+ for (index = 0; index < nBytes; index++)
31
32
+ printf("%02x", xmain[index] & 0xFF);
33
+ if (index != nBytes - 1)
34
+ printf(" ");
35
36
37
+ printf("\n");
38
+ return (0);
39
+}
0 commit comments