forked from ruv1nce/42-exam_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrainfuck.c
More file actions
59 lines (56 loc) · 759 Bytes
/
Copy pathbrainfuck.c
File metadata and controls
59 lines (56 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <unistd.h>
int main(int argc, char **argv)
{
char string[2048];
char *str;
char *ptr;
int i;
if (argc != 2)
return (0);
i = 0;
while (i < 2048)
{
string[i] = 0;
i++;
}
ptr = *(argv + 1);
str = &string[0];
while (*ptr)
{
if (*ptr == '>')
str++;
else if (*ptr == '<')
str--;
else if (*ptr == '+')
(*str)++;
else if (*ptr == '-')
(*str)--;
else if (*ptr == '.')
write(1, str, 1);
else if (*ptr == '[' && !*str)
{
i = 1;
while (i > 0)
{
ptr++;
if (*ptr == '[')
i++;
else if (*ptr == ']')
i--;
}
}
else if (*ptr == ']' && *str)
{
i = 1;
while (i > 0)
{
ptr--;
if (*ptr == ']')
i++;
else if (*ptr == '[')
i--;
}
}
ptr++;
}
}