Mercurial
comparison wedding/main.c @ 12:de54585a40f1
Adding bun and node modules.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 02 Oct 2025 14:39:48 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 11:f33d9ff8b6e8 | 12:de54585a40f1 |
|---|---|
| 1 #include "dowa/dowa.h" | |
| 2 | |
| 3 | |
| 4 size_t Dowa_File_ReadLine(FILE *restrict stream, char *buffer, size_t buffer_size) | |
| 5 { | |
| 6 char c; | |
| 7 size_t res = 0; | |
| 8 while ((c = getc(stream)) != EOF && c != '\n') | |
| 9 { | |
| 10 if (res + 1 > buffer_size) | |
| 11 break; | |
| 12 buffer[res++] = c; | |
| 13 } | |
| 14 buffer[res] = '\0'; | |
| 15 return res; | |
| 16 } | |
| 17 | |
| 18 | |
| 19 int main(void) | |
| 20 { | |
| 21 char c; | |
| 22 char *comma, *curr; | |
| 23 char **keys; | |
| 24 FILE *f = fopen("wedding/invities.csv", "rb"); | |
| 25 if (!f) | |
| 26 perror("fopen\n"); | |
| 27 | |
| 28 char *line = malloc(128); | |
| 29 | |
| 30 Dowa_PArena p_csv_area = Dowa_Arena_Create(4048); | |
| 31 keys = Dowa_Arena_Allocate(p_csv_area, sizeof(char*) * 10); | |
| 32 | |
| 33 while (Dowa_File_ReadLine(f, line, 128) > 0) | |
| 34 { | |
| 35 curr = line; | |
| 36 int pos = 0 ; | |
| 37 | |
| 38 while (1) | |
| 39 { | |
| 40 comma = memchr(curr, ',', strlen(curr)); | |
| 41 if (!comma) | |
| 42 break; | |
| 43 size_t diff = comma - curr; | |
| 44 keys[pos] = Dowa_Arena_Allocate(p_csv_area, diff+1); | |
| 45 memcpy(keys[pos], curr, diff); | |
| 46 curr = comma+1; | |
| 47 pos += 1; | |
| 48 } | |
| 49 | |
| 50 int last = strlen(curr); | |
| 51 keys[pos] = Dowa_Arena_Allocate(p_csv_area, last); | |
| 52 memcpy(keys[pos], curr, last); | |
| 53 | |
| 54 for (pos = 0; pos < 10; pos++) | |
| 55 { | |
| 56 if (!keys[pos]) | |
| 57 break; | |
| 58 printf("%s, ", keys[pos]); | |
| 59 } | |
| 60 printf("\n\n"); | |
| 61 } | |
| 62 | |
| 63 return 0; | |
| 64 } |