Naming conventions for .c files
What you'll learn: How to name your source files so they are professional, portable, and easy for the compiler to find.
The "Digital Label"
Think of a .c file like a physical folder in a filing cabinet. If you label a folder "Stuff," you’ll be lost in a week. If you label it "Tax_Returns_2023," you know exactly what’s inside. In C programming, your filename tells both the human programmer and the computer's "compiler" tool what to expect.
Rule 1: Use the .c extension
The most important rule is the suffix. C source code files must end in .c. This is a signal to your toolchain. When you tell your compiler to run, it looks for that .c tag to know, "Okay, this is C code I need to translate into a program." Without it, the compiler might ignore the file or treat it like plain text.
Rule 2: Keep it lowercase and simple
While modern computers can handle spaces and capital letters, C tradition (and many professional tools) prefers lowercase_snake_case.
- Bad:
My First Program.c(Spaces can break command-line tools). - Bad:
Calculation.C(Some systems treat.Cas C++, which is a different language!). - Good:
hello_world.cortemp_converter.c.
Using underscores (_) instead of spaces ensures that when you type the filename into a terminal, the computer doesn't get confused and think you are typing two different commands.
Example of a well-named file
If you were writing a program to calculate the area of a circle, your file structure would look like this:
/* File saved as: circle_area.c */
#include <stdio.h>
int main() {
printf("Ready to calculate!\n");
return 0;
}
Why consistency matters
As your projects grow, you might have dozens of files. If half are named MainCode.c and the other half are math_functions.c, your project becomes a messy "junk drawer." Sticking to lowercase names with underscores is a "handshake" between you and other programmers, signaling that you follow standard professional conventions.
Key takeaway
Always name your files in lowercase, use underscores instead of spaces, and ensure they end in a lowercase .c.