forked from b-k/21st-Century-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_methods.c
34 lines (29 loc) · 896 Bytes
/
print_methods.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
/* Compile with:
CFLAGS="-g -Wall -std=gnu11 -O3" make print_methods
*/
#include <stdio.h>
#include "print_typedef.h"
static void print_ad(textlist_s *in){
printf("BUY THIS %s!!!! Features:\n", in->title);
for (int i=0; i< in->len; i++)
printf("∙ %s\n", in->items[i]);
}
static void print_song(textlist_s *in){
printf("♫ %s ♫\nLyrics:\n\n", in->title);
for (int i=0; i< in->len; i++)
printf("\t%s\n", in->items[i]);
}
textlist_s save = {.title="God Save the Queen",
.len=3, .items=(char*[]){
"There's no future", "No future", "No future for me."},
.print=print_song};
textlist_s spend = {.title="Never mind the Bollocks LP",
.items=(char*[]){"By the Sex Pistols", "Anti-consumption themes"},
.len=2, .print=print_ad};
#ifndef skip_main
int main(){
save.print(&save);
printf("\n-----\n\n");
spend.print(&spend);
}
#endif