Skip to content

Instantly share code, notes, and snippets.

@flatmap13
Created January 13, 2013 10:51
Show Gist options
  • Save flatmap13/4523512 to your computer and use it in GitHub Desktop.
Save flatmap13/4523512 to your computer and use it in GitHub Desktop.
Small command line application to translate error numbers to readable messages. You can supply multiple error numbers via command line arguments. If zero arguments are supplied, the app asks for an error number interactively.
#include <stdio.h>
#include <string.h>
void print_error(int);
int main(int argc, char *argv[])
{
int err_num;
if(argc > 1) {
while(--argc > 0 && ++argv) {
if(err_num = atoi(*argv))
print_error(err_num);
else
printf("warning: '%s' is not a valid error number\n", *argv);
}
} else {
printf("input error code: ");
scanf("%d", &err_num);
print_error(err_num);
}
return 0;
}
void print_error(int err_num)
{
printf("%d: %s\n", err_num, strerror(err_num));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment