-
Notifications
You must be signed in to change notification settings - Fork 1
/
csvlib.c
37 lines (31 loc) · 798 Bytes
/
csvlib.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
#include "csvlib.h"
void gerar_csv(unsigned int tam, char *filename)
{
FILE *fp;
fp = fopen(filename, "w");
if (!fp) {
puts("Erro ao abrir o arquivo");
exit(1);
}
//Gerar enumeração
for (unsigned int i = 1; i <= ((tam*tam)); i++) {
fprintf(fp, "%u, ", i);
}
fprintf(fp, " %u \n",(tam*tam+1));
fclose(fp);
}
void preencher_csv(unsigned char *m, unsigned int tam, char *filename, unsigned int rotulo)
{
FILE *fp;
fp = fopen(filename, "a");
if (!fp) {
puts("Erro ao abrir o arquivo");
exit(1);
}
//Preencher com os valores
for (unsigned int k = 0; k < (tam*tam); k++) {
fprintf(fp, "%hhu, ", *(m + k));
}
fprintf(fp, "%s\n", rotulo ? "stroma" : "epithelium");
fclose(fp);
}