forked from b-k/21st-Century-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpapersize.c
More file actions
24 lines (21 loc) · 704 Bytes
/
papersize.c
File metadata and controls
24 lines (21 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Compile with:
export CFLAGS="-g -Wall -std=gnu11 -O3" #the usual.
make papersize
*/
#include <stdio.h>
#include <strings.h> //strcasecmp (from POSIX)
#include <math.h> //NaN
typedef struct {
double width, height;
} size_s;
size_s width_height(char *papertype){
return
!strcasecmp(papertype, "A4") ? (size_s) {.width=210, .height=297}
: !strcasecmp(papertype, "Letter") ? (size_s) {.width=216, .height=279}
: !strcasecmp(papertype, "Legal") ? (size_s) {.width=216, .height=356}
: (size_s) {.width=NAN, .height=NAN};
}
int main(){
size_s a4size = width_height("a4");
printf("width= %g, height=%g\n", a4size.width, a4size.height);
}