Cleanup code. Remove VLAs. Support c89.
[OptFetch.git] / example.c
blob193d5cc14d9325d8b0d5be8ee3563820c8f5ec8d
1 #include "optfetch.h"
2 #include <stdio.h>
3 #include <stdbool.h>
5 int main(int argc, char **argv) {
6 bool debug = false;
7 char *name = NULL;
8 float boat = 0.0;
10 struct opttype opts[] = {
11 {"debug", 'd', OPTTYPE_BOOL, &debug},
12 {"name", 'n', OPTTYPE_STRING, &name},
13 {"boat", 'b', OPTTYPE_FLOAT, &boat},
14 {0}};
16 fetchopts(&argc, &argv, opts);
18 if (debug) {
19 printf("Did debug.\n");
22 printf("Hi. My name is %s. What's yours?\n", name);
24 printf("My boat is %f feet long. How about yours?\n", boat);
26 printf("Looks like I have %d argument%s left over. Fancy that now!\n", argc, (argc == 1) ? "" : "s");
28 if (argc) {
29 printf("They are:\n");
30 for (int i = 1; i <= argc; i++) {
31 printf("* %s\n", argv[i]);
35 return 0;