Programs are generated from text files whose filenames use predefined file extensions. These are known as source files, or source code files. For C, the .c file extension indicates a C source code file. An .h extension (which is present in our Hello, world! program) indicates a C header file. The compiler looks for .c and .h files as it encounters them and because each has a different purpose, it treats each differently as well. Other languages have their own file extensions; the contents of a source code file should match the language that the compiler expects.
To create and modify C files, you will need a plain text editor. This is a program that allows you to open, modify, and save plain text without any formatting such as font size, font family, font style, and much more. For instance, on Windows, Notepad is a plain text editor while Word is not. The plain text editor should have the following capabilities:
- File manipulation: Open a file, edit a file, save the file and any changes that have been made to it, and save the file with another name.
- The ability to navigate the file: Move up, down, left, right, to the beginning of the line, end of the line, beginning of the file, end of the file, and so on.
- Text manipulation: Insert text, delete text, insert line, delete line, selection, cut, copy, paste, undo/redo, and so on.
- Search and replace: Find text, replace text, and so on.
The following capabilities are handy but not essential:
- Automatic indentation
- Syntax coloring for the specific programming language
- Automatic periodic saving
Almost any plain text editor will do. Do not get too caught up in the features of any given text editor. Some are better than others; some are free, while others are costly, and may not immediately be worth the expense (perhaps later, one or more might be worthwhile but not at this time), and none will do 100% of what you might want them to do.
Here are some free plain text editors worth installing on your computer and trying out:
- Everywhere:Nano, which runs in a Terminal; a moderate learning curve.
- Linux/Unix:
- Vim, or vi: Runs in a Terminal; a moderate learning curve. It is on every Linux/Unix system, so it's worth learning how to use its basic features.
- gedit: A powerful general-purpose editor.
- Emacs: An everything and the kitchen sink editor; a very large learning curve.
- Windows:
- Notepad: Very simple – sometimes too simple for programming – but included in every Windows system.
- Notepad++: A better version of Notepad with many features for programming.
- macOS only: BBEdit (free version), which is a full-featured GUI programming text editor.
There are many, many text editors, each with its own strengths and weaknesses. Pick a text editor and get used to it. Over time, as you use it more and more, it will become second nature.