/* gdb_test.c Jeff Ondich, 14 February 2022 Major simplifications, 17 Oct 2023 Compile like this: gcc -o gdb_test -Wall -Werror -g -Og gdb_test.c */ #include #include int factorial(int n) { if (n <= 1) { return 1; } int result = factorial(n - 1); result = n * result; return result; } void print_usage(char *command_name) { fprintf(stderr, "Usage: %s [integer]\n", command_name); } int main(int argc, char *argv[]) { if (argc != 2) { print_usage(argv[0]); return 1; } int n = 0; int matches = sscanf(argv[1], "%d", &n); if (matches != 1) { // what's this about? print_usage(argv[0]); return 1; } int result = factorial(n); printf("%d! = %d\n", n, result); return 0; }