-
Notifications
You must be signed in to change notification settings - Fork 0
/
notacao.c
58 lines (47 loc) · 840 Bytes
/
notacao.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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define TAMANHO 5
typedef struct
{
uint8_t a;
char b;
} pacote;
pacote* aloca(uint8_t tamanho)
{
pacote* pacotes;
pacotes = (pacote*)malloc(tamanho*sizeof(pacote));
if(!pacotes) return 0;
return pacotes;
}
void acessa_como_vetor(pacote vetor[], uint8_t tamanho)
{
uint8_t i;
for(i = 0; i < tamanho; i++)
{
vetor[i].a = i;
vetor[i].b = 'a' + i;
printf("\n %u, %c \n", (unsigned)vetor[i].a, vetor[i].b);
}
}
void acessa_como_ponteiro(const pacote* p, uint8_t tamanho)
{
pacote* t;
uint8_t i;
t = p;
for(i = 0; i < tamanho; i++)
{
t->a = i;
t->b = 'a' + i;
printf("\n %u, %c \n", (unsigned)t->a, t->b);
t++;
}
}
int main()
{
pacote* p;
p = aloca(TAMANHO);
acessa_como_vetor(p, TAMANHO);
acessa_como_ponteiro(p, TAMANHO);
return 0;
}