How to compile and run C code in Notepad
To compile and run C in Notepad , install g (via MinGW), write code, then configure Run command with: cmd /k g "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)$(NAME_PART)" && "$(CURRENT_DIRECTORY)\$(NAME_PART).exe", save as shortcut (e.g., Ctrl F10) for execution.

To compile and run C code in Notepad , you need to use an external compiler (like MinGW or g ) and configure Notepad to execute the compilation and running commands. Here's how you can set it up step by step.
1. Install a C Compiler (g )
You must have a C compiler installed on your system. The most common choice for Windows is MinGW (Minimalist GNU for Windows), which includes g .
- Download MinGW-w64 from https://www.mingw-w64.org/ or use MSYS2 to install it.
- During installation, make sure to add the bin directory (e.g.,
C:\mingw64\bin) to your system's PATH environment variable. - Verify installation: Open Command Prompt and type
g --version. If you see version info, it’s working.
2. Write Your C Code in Notepad
Open Notepad and write a simple C program, for example:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
Save the file with a .cpp extension, like hello.cpp.
3. Configure Notepad to Compile and Run
Use Notepad 's Run feature to call external commands.
- Press F5 or go to Run → Run...
- To compile and run, enter this command:
cmd /k g "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART)" && "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"
-
$(FULL_CURRENT_PATH): Full path of the current file. -
$(CURRENT_DIRECTORY): Folder of the file. -
$(NAME_PART): Filename without extension. -
cmd /k: Keeps the command window open after execution.
Click Save, give it a name like Compile & Run C , assign a shortcut (e.g., Ctrl F10), then click OK.
4. Use the Shortcut to Compile and Run
Now, whenever you want to compile and run your C code:
- Press your saved shortcut (e.g., Ctrl F10).
- A command prompt will appear showing compilation errors (if any) and run the output.
- If there are no errors, you’ll see your program’s output (e.g., "Hello, World!").
Basically, Notepad acts as a lightweight editor while relying on g and the command line to do the actual compiling and running. It's not a full IDE, but it works well for small projects and learning.
The above is the detailed content of How to compile and run C code in Notepad. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20572
7
13672
4




