err 2.0.0
Small error-printing library written in C
Loading...
Searching...
No Matches
hello.c

This example is an introduction to using the library.

Note the different situations in which the two functions are called. errc() is called when the program encounters a state that it doesn't know how to handle. warn() is called when an unusual but managable condition is found.

/**
* @example hello.c
* This example is an introduction to using the library.
*
* Note the different situations in which the two functions are called. errc()
* is called when the program encounters a state that it doesn't know how to
* handle. warn() is called when an unusual but managable condition is found.
*/
#include <stdio.h>
#include <stdlib.h>
#include "../err.h"
int
main(int argc, char *argv[])
{
char *word;
if (argc > 2)
errc(argc, "multiple arguments provided");
else if (argc == 1) {
warn("no argument provided, using default word\n");
word = "world";
} else
word = argv[1];
printf("Hello, %s!\n", word);
return EXIT_SUCCESS;
}
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