#include #include #include #include #include #define META_FORMAT "%%#ll%c\n" static char *argv0; static unsigned long long conversion(char *nombre) { errno = 0; unsigned long long v = strtoull(nombre, NULL, 0); if (errno == ERANGE) { fprintf(stderr, "%s: %s: nombre trop grand\n", argv0, nombre); exit(EXIT_FAILURE); } return v; } static void usage(void) { fprintf(stderr, "Usage: %s [-o|-x] «nombre»\n", argv0); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { char format[sizeof META_FORMAT]; char specification = 'u'; int indice_valeur = 1; argv0 = argv[0]; if (argc == 3) { if (strcmp(argv[1], "-o") == 0 || strcmp(argv[1], "-x") == 0) specification = argv[1][1]; else usage(); indice_valeur = 2; } else if (argc != 2) usage(); unsigned long long v = conversion(argv[indice_valeur]); snprintf(format, sizeof format, META_FORMAT, specification); printf(format, v); return EXIT_SUCCESS; }