improve list encode/decode

This commit is contained in:
Rongsong Shen 2025-04-28 10:32:18 +08:00
parent 3a7ae150b8
commit 40006c00d2
3 changed files with 18 additions and 13 deletions

View file

@ -20,7 +20,7 @@ int encode() {
uint32_t magic1[2] = {
1101,1012
};
chapter_t chapters[3] = {
chapter_t chapters_[3] = {
{.caption ="Chapter1",
.start =1,
.end=99},
@ -31,6 +31,9 @@ int encode() {
.start = 151,
.end=199}
};
chapter_t* chapters[3] = {
&chapters_[0], &chapters_[1], &chapters_[2]
};
publish_t publish = {
.isbn = 335677,
.year =2001
@ -87,10 +90,10 @@ int decode() {
printf("chapters(%d):\n", book->n_chapters);
for(i = 0; i < book->n_chapters; i ++) {
printf("\tcaption: %s\n", book->chapters_[i].caption);
printf("\tcaption: %s\n", book->chapters_[i]->caption);
printf("\tfrom %d to %d\n",
book->chapters_[i].start,
book->chapters_[i].end);
book->chapters_[i]->start,
book->chapters_[i]->end);
}
printf("ISBN: %lu year: %u\n",