-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_isneg.c
40 lines (34 loc) · 922 Bytes
/
my_isneg.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
/* *****************************************************************************
** Write a function displays 'N' or 'P' depending on the sign of the integer
** passed as parameter. if n is negative, display 'N', otherwise, if n is
** positive or null then display 'P'.
**
** The function shall be prototyped as follows:
** int my_isneg(int n);
**
** Additional rule:
** The function shall return the number of characters printed out.
** ****************************************************************************/
#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
#endif
int my_isneg(int n);
int my_isneg(int n)
{
return ((int)write(1, n < 0 ? "N" : "P", 1));
}
#ifdef MY_ISNEG
int main()
{
write(1, "my_isneg(0) = ", 14);
my_isneg(0);
write(1, "\nmy_isneg(1) = ", 15);
my_isneg(1);
write(1, "\nmy_isneg(-1) = ", 16);
my_isneg(-1);
write(1, "\n", 1);
return (0);
}
#endif /* !MY_ISNEG */