-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_2.c
77 lines (70 loc) · 2.13 KB
/
errors_2.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
71
72
73
74
75
76
77
/*
* File: errors_2.c is the file name
* Authors: Faith Nyaberi
* Peter Ochieng
*/
#include "monty.h"
int short_stack_error(unsigned int line_number, char *op);
int div_error(unsigned int line_number);
int pop_error(unsigned int line_number);
int div_error(unsigned int line_number);
int pchar_error(unsigned int line_number, char *message);
/**
* pop_error - Prints the pop error messages for empty stacks.
* @line_number: Line number in script where error occured.
*
* Return: (EXIT_FAILURE) always.
*/
int pop_error(unsigned int line_number)
{
fprintf(stderr, "L%u: can't pop an empty stack\n", line_number);
return (EXIT_FAILURE);
}
/**
* pint_error - Prints pint error messages for empty stacks.
* @line_number: Line number in Monty bytecodes file where error occurred.
*
* Return: (EXIT_FAILURE) always.
*/
int pint_error(unsigned int line_number)
{
fprintf(stderr, "L%d: can't pint, stack empty\n", line_number);
return (EXIT_FAILURE);
}
/**
* short_stack_error - Prints monty math function error messages
* for stacks/queues smaller than two nodes.
* @line_number: Line number in Monty bytecodes file where error occurred.
* @op: Operation where the error occurred.
*
* Return: (EXIT_FAILURE) always.
*/
int short_stack_error(unsigned int line_number, char *op)
{
fprintf(stderr, "L%u: can't %s, stack too short\n", line_number, op);
return (EXIT_FAILURE);
}
/**
* div_error - Prints division error messages for division by 0.
* @line_number: Line number in Monty bytecodes file where error occurred.
*
* Return: (EXIT_FAILURE) always.
*/
int div_error(unsigned int line_number)
{
fprintf(stderr, "L%u: division by zero\n", line_number);
return (EXIT_FAILURE);
}
/**
* pchar_error - Prints pchar error messages for empty stacks
* empty stacks and non-character values.
* @line_number: Line number in Monty bytecodes file where error occurred.
* @message: The corresponding error message to print.
*
* Return: (EXIT_FAILURE) always.
*/
int pchar_error(unsigned int line_number, char *message)
{
fprintf(stderr, "L%u: can't pchar, %s\n", line_number, message);
return (EXIT_FAILURE);
}