-
Notifications
You must be signed in to change notification settings - Fork 0
/
prints.c
70 lines (65 loc) · 1.84 KB
/
prints.c
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
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* prints.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zcarde <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/24 05:58:44 by zcarde #+# #+# */
/* Updated: 2015/03/24 06:58:48 by zcarde ### ########.fr */
/* */
/* ************************************************************************** */
#include "computor.h"
void print_error(char *str)
{
ft_putstr("\033[31m");
ft_putstr(str);
ft_putendl("\033[0m");
exit(-1);
}
void print_elem(t_lst *elem, int first)
{
if (first && elem->term.a >= 0)
dprintf(1, " + ");
else if (elem->term.a < 0)
{
if (!first)
dprintf(1, "- ");
else
dprintf(1, " - ");
}
if (elem->term.a != 1 || elem->term.p == 0)
dprintf(1, "%g", ABS(elem->term.a));
if (elem->term.a != 1)
{
if (elem->term.p == 1)
dprintf(1, " * X");
else if (elem->term.p != 0)
dprintf(1, " * X^%d", elem->term.p);
}
else
{
if (elem->term.p == 1 && elem->term.a != 1)
dprintf(1, "%g * X", ABS(elem->term.a));
else if (elem->term.p != 0)
dprintf(1, "%g * X^%d", ABS(elem->term.a), elem->term.p);
}
}
void print_lst(t_lst *beg)
{
t_lst *temp;
int first;
first = 0;
temp = beg;
while (temp)
{
if (temp->term.a != 0)
{
print_elem(temp, first);
first++;
}
temp = temp->next;
}
if (first == 0)
dprintf(1, "0");
}