err 2.0.0
Small error-printing library written in C
Loading...
Searching...
No Matches
hello.c
1/**
2 * @example hello.c
3 * This example is an introduction to using the library.
4 *
5 * Note the different situations in which the two functions are called. errc()
6 * is called when the program encounters a state that it doesn't know how to
7 * handle. warn() is called when an unusual but managable condition is found.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12
13#include "../err.h"
14
15int
16main(int argc, char *argv[])
17{
18 char *word;
19
21
22 if (argc > 2)
23 errc(argc, "multiple arguments provided");
24 else if (argc == 1) {
25 warn("no argument provided, using default word\n");
26 word = "world";
27 } else
28 word = argv[1];
29
30 printf("Hello, %s!\n", word);
31
32 return EXIT_SUCCESS;
33}
char * program_invocation_name
Global value for the program's name.
Definition: err.c:29
void warn(const char *fmt,...)
Prints a formatted warning message to stderr.
Definition: err.c:84
void errc(const int code, const char *fmt,...)
Prints a formatted error message to stderr and exits with the given exit code.
Definition: err.c:110