Callygraphs/example.c
hax a519352291 Welcome example.c
Signed-off-by: hax <hax@lainlounge.xyz>
2025-01-05 18:17:02 +00:00

57 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
// Function prototypes
static void foo(int n);
static void bar(int n);
static void baz(int n);
/**
* Main function
* Entry point of the program.
*/
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <integer>\n", argv[0]);
return EXIT_FAILURE;
}
char *endptr;
long input = strtol(argv[1], &endptr, 10);
if (*endptr != '\0' || input <= 0 || input > INT_MAX) {
fprintf(stderr, "Invalid input. Please provide a positive integer.\n");
return EXIT_FAILURE;
}
foo((int)input);
return EXIT_SUCCESS;
}
/**
* Function: foo
* Description: Calls the `bar` function.
*/
void foo(int n) {
printf("In foo with n = %d\n", n);
bar(n);
}
/**
* Function: bar
* Description: Calls the `baz` function.
*/
void bar(int n) {
printf("In bar with n = %d\n", n);
baz(n);
}
/**
* Function: baz
* Description: Final function in the call chain.
*/
void baz(int n) {
printf("In baz with n = %d\n", n);
// Placeholder for actual logic
}