Skip to content

Commit 6c14bb3

Browse files
committed
added: 100-main_opcodes.c
1 parent fb37e52 commit 6c14bb3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -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+
printf("Error\n");
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

Comments
 (0)