-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_charstr.c
45 lines (43 loc) · 947 Bytes
/
p_charstr.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
#include "monty.h"
/**
* pstr - prints the string starting at the top of the stack,
* followed by a new line.
* @head: double pointer to head
* @count: counter
* Return: void
*/
void pstr(stack_t **head, unsigned int count __attribute((unused)))
{
stack_t *c = *head;
while (c && (c->n != 0) && ((c->n) > 32) && (( c->n) < 128))
{
printf("%c", c->n);
c = c->next;
}
putchar('\n');
}
/**
* pchar - prints the char at the top of the stack, followed by a new line.
* @head: double pointer to head node
* @count: countet
* Return: void
*/
void pchar(stack_t **head, unsigned int count)
{
int stack;
if (!head || !(*head))
{
fprintf(stderr, "L%u: can't pchar, stack empty\n", count);
free_stack();
exit(EXIT_FAILURE);
}
stack = 0;
stack = (*head)->n;
if ((stack < 33) || (stack > 127))
{
fprintf(stderr, "L%u: can't pchar, value out of range\n", count);
exit(EXIT_FAILURE);
}
putchar(stack);
putchar('\n');
}