-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendas.c
92 lines (72 loc) · 1.72 KB
/
vendas.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
#define _GNU_SOURCE 1
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "vendas.h"
struct venda {
char * cliente;
char * produto;
char promo;
float preco;
int quantidade;
int mes;
int filial;
};
VENDA strToVenda(char * str){
char* currentTok;
VENDA v;
v = malloc(sizeof(VENDA)*4);
currentTok = strtok(str, " ");
v -> produto = strdup(currentTok);
currentTok = strtok(NULL, " ");
v -> preco = atof(currentTok);
currentTok = strtok(NULL, " ");
v -> quantidade = atoi(currentTok);
currentTok = strtok(NULL, " ");
v -> promo = currentTok[0];
currentTok = strtok(NULL, " ");
v -> cliente = strdup(currentTok);
currentTok = strtok(NULL, " ");
v -> mes = atoi(currentTok);
currentTok = strtok(NULL, " ");
v -> filial = atoi(currentTok);
return v;
}
void printVenda(VENDA v){
if(v != NULL)
printf("%s %f %d %c %s %d %d\n", v -> produto,
v -> preco,
v -> quantidade,
v -> promo,
v -> cliente,
v -> mes,
v -> filial);
else
printf("NULL\n");
}
void destroyVenda(VENDA v){
free(v -> produto);
free(v -> cliente);
free(v);
}
char * getProduto(VENDA v){
return (v -> produto);
}
char * getCliente(VENDA v){
return (v -> cliente);
}
float getPreco(VENDA v){
return (v -> preco);
}
int getQuantidade(VENDA v){
return (v -> quantidade);
}
char getPromo(VENDA v){
return (v -> promo);
}
int getMes(VENDA v){
return (v -> mes);
}
int getFilial(VENDA v){
return (v -> filial);
}