-
Notifications
You must be signed in to change notification settings - Fork 3
/
output.c
57 lines (49 loc) · 1.61 KB
/
output.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
//
// Created by Ajay on 17-09-2017.
//
#include <stdio.h>
#include <stdlib.h>
#include "output.h"
#include <string.h>
cellptr data_expand(byte_array val){
int i=1;
cellptr new_cell = NULL;
cellptr first_cell = NULL;
char temp_array[255];
//val[0] contains the length of the data in a byte array
while(i < val[0]) {
new_cell = malloc(sizeof(CellData));
if (new_cell == NULL) {
printf("error: data_expand: memory allocation failed!");
exit(EXIT_FAILURE);
}
new_cell->dt = (uint8_t) *(val+i++);
new_cell->cell_name_len = (uint8_t ) *(val+i++);
strncpy(temp_array, (char *) (val + i), new_cell->cell_name_len);
temp_array[new_cell->cell_name_len] = '\0';
new_cell->cell_name = strdup(temp_array);
i = i + new_cell->cell_name_len;
new_cell->val_len = (uint8_t)*(val+i++);
strncpy(temp_array, (char *) (val + i), new_cell->val_len);
temp_array[new_cell->val_len] = '\0';
i = i + new_cell->val_len;
switch (new_cell->dt) {
case INT:
new_cell->val.ival = atoi(temp_array);
break;
case FLOAT:
new_cell->val.fval = atof(temp_array);
break;
case STRING:
new_cell->val.sval = strdup(temp_array);
break;
default:
printf("\a error : data_expand!");
}
new_cell->next_cell=NULL;
first_cell = linked_list(first_cell, new_cell);
new_cell = NULL;
free(new_cell);
}
return first_cell;
}