C
Beginner
1 min read
The Structure of a C Program
Example
/*
* structure.c — anatomy of a well-structured C file.
*/
#include <stdio.h> /* printf, scanf */
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE */
/* --- Constants defined at the top --- */
#define MAX_ITEMS 100
#define PROGRAM_VERSION "1.0"
/* --- Function prototype (declaration before use) --- */
void print_banner(const char *version);
/* --- main: program entry point --- */
int main(void)
{
print_banner(PROGRAM_VERSION);
int count = 0;
printf("Enter a number (0 to quit):\n");
while (scanf("%d", &count) == 1 && count != 0) {
printf("You entered: %d\n", count);
}
return EXIT_SUCCESS;
}
/* --- Function definition --- */
void print_banner(const char *version)
{
printf("=== My C Program v%s ===\n", version);
}