forked from alessandrots/estudoFontesC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
103 lines (77 loc) · 1.81 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include "stack/stack.h"
void makeMenu(){
printf ("\t 0 - Exit \n");
printf ("\t 1 - Push Item \n");
printf ("\t 2 - Search an Item \n");
printf ("\t 3 - List itens from stack \n");
printf ("\t 4 - Stack size \n");
printf ("\t 5 - Delete an Item \n");
printf ("\n\nChoice one of the options above = ");
}
int main (void)
{
char ch=0;
char option_typed=0;
int item_typed, founded, res_scan;
struct stack *num_stack;
res_scan = system ("clear");
makeMenu();
option_typed = getchar ();
num_stack = NULL;
while(ch != '0')
{
switch (option_typed)
{
case '0':
exit(EXIT_SUCCESS);
case '1':
printf("\nType a number: ");
res_scan = scanf("%d", &item_typed);
num_stack = push (num_stack, item_typed);
break;
case '2':
printf ("Type a number to be searched: ");
res_scan = scanf ("%d", &item_typed);
founded = search_by_item (num_stack, item_typed);
if (founded > 0)
{
printf ("\nThe item was found in this position: %d . \n\n", founded);
}
else
{
printf ("\nItem not found.\n\n");
}
break;
case '3':
list_stack (num_stack);
break;
case '4':
stack_size (num_stack);
break;
case '5':
printf ("\nType a number: ");
res_scan = scanf ("%d", &item_typed);
num_stack = remove_by_value (num_stack, item_typed);
printf ("Stack updated.\n");
list_stack (num_stack);
stack_size (num_stack);
break;
}
if (option_typed !='\n')
{
/*
* res_scan = system ("clear");
* TODO
* passar mensagem referente a opção como parametro
* da funcao makeMenu afim de nao perde-la apos a limpeza de tela
*/
makeMenu ();
}
option_typed = getchar ();
}
printf ("\n %d", res_scan);
free (num_stack);
return 0;
}