Welcome example.c
Signed-off-by: hax <hax@lainlounge.xyz>
This commit is contained in:
parent
e33a82abae
commit
a519352291
1 changed files with 57 additions and 0 deletions
57
example.c
Normal file
57
example.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#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
|
||||
}
|
Loading…
Add table
Reference in a new issue