search
HomeDevelopment ToolsnotepadHow to use notepad to compile c language

How to use notepad to compile c language

1. Previous story

The IDE (integrated development environment) I usually use is Dev-Cpp, because it is just In the learning stage, the code is still less than a thousand lines. Personally, I don’t think there is a need for a comprehensive version like VS, and there are some aspects of VC6.0 that are not pleasing to the eye (not just aesthetically).

But recently I discovered that when copying the C code file to Ubuntu 18.04 for compilation and running, the Chinese characters will always be garbled. Because of the encoding (character encoding) problem, Ubuntu only recognizes UTF-8, and Windows only recognizes ANSI. Although I can make VIM display ANSI in Ubtuntu, I can't make it display in the terminal. Dev-Cpp on Windows cannot set the encoding to UTF-8, so I want to use Notepad as Editor and add Compiler. Function.

Environment: win7. Notepad. Dev-Cpp.

Recommended tutorial: Notepad usage tutorial

2. Step

1. Configure the compiler

Download and install MinGW from the official website

change:

How to use notepad to compile c language

Select "mark for installation" of "mingw32-gcc-g -bin" and select "Apply Changes" of "Installation" in the upper right corner. There were no other problems when I didn't install the other items. Later, other problems arose and I had to ask for insurance before installing them. In total, just under 400MB was installed.

Related recommendations: "Notepad usage graphic tutorial"

2. Edit environment variables

How to use notepad to compile c language

Control Panel\All Control Panel Items\System, Advanced System Settings→Environment Variables, find the PATH variable in the "Administrator's User Variables" column, create a new one if there is none, edit if there is one, the variable name is "PATH", the variable value Add a "C:\MinGW\bin;" on the original basis. This value is related to the location where each person installs MinGW and varies from person to person. The significance of ";" is that when the value of PATH has multiple items, use it to separate these items.

3. Two methods to check whether the first two steps are successful

How to use notepad to compile c language

Enter the cmd console and enter gcc -v or g - vView the compiler version that has been added to the environment variables. It is normal to display the content in the yellow box, indicating that the first two steps were successful.

Create a simple C source code file to ensure that the code can run correctly. For example, Hello.cpp:

//Hello.cpp
#include<iostream>  
using namespace std;
int main()
{
    cout<<"Hello world, 世界你好!"<<endl;
    return 0;  
}

In the cmd console, cd to the directory of the source code, then execute g Hello.cpp -o Hello.exe, and then execute the Hello.exe /k command. It can run normally. It shows that the first two steps are fine.

The former command is to use the g compiler to compile the source code and output the exe file to this directory. The latter command is to run the exe file (/k parameter makes it stay in the program interface after running, as opposed to / c will close it. That is the comparison between keep and close). The first two commands can actually be combined into one using "&&", that is, g Hello.cpp -o && Hello.exe Hello.exe /k.

We are already more than half successful here, because as you can see, you can already compile and run the source code in the cmd console. Giving Notepad this ability only allows Notepad to "compile the currently opened source file in one step". Just use cmd to execute compilation and run commands."

4. Notepad adds run command

Open Notepad and press F5 to bring up "Run". Copy the command mentioned later and run it. It is recommended to save it with any name.

How to use notepad to compile c language

You can also find “Run (R)” in the toolbar

Referenced a number of information about Notepad run commands and cmd commands, modified My last command is cmd /k pushd "$(CURRENT_DIRECTORY)" && g -o "$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" && "$(NAME_PART)".exe & PAUSE & EXIT (no branch, It is a whole command). To understand this command, you can divide it into six, namely:

(1) cmd /k: Open the cmd console, run the program and let it stay without automatically closure.

 (2) pushd "$(CURRENT_DIRECTORY)": Change the working path to the path where the source file is located. For example, 'pushd E:\kkk' is equivalent to e: and then cd kkk in cmd. This command is in the source code This is especially important when you want to call a file in the same directory and only write a relative path. Because Notepad's default working path is its own installation path.

  (3) g -o "$(NAME_PART).exe" "$(FULL_CURRENT_PATH)": Call the compiler g.exe in the environment variable to compile the source code into an exe file with the same name and output it to the same path.

  (4) "$(NAME_PART)".exe: Run the executable file compiled from the source code.

  (5) PAUSE: Pause, prompting "Press any key to continue", and cooperate with the next command to achieve the effect of "Press any key to close". If neither is available, the program will be closed in seconds after running.

 (6) EXIT: Close the cmd console. If not, press any key to return to the cmd command console, waiting for the next command to be entered.

 ·$(CURRENT_DIRECTORY) represents the path of the directory where the file is located.

 ·$(NAME_PART) indicates the file name without the suffix part of the file.

 ·$(FULL_CURRENT_PATH) represents the current complete file path.

 ·Double quotation marks (half-width): Used to prevent directories or file names from containing spaces.

 ·"&&" and "&": The former means that the previous command is executed normally before the next command is executed, and if it is abnormal, the next command is not executed; the latter is worry-free. For example, the last two subcommands after dividing into six means that regardless of whether the source code is compiled and run successfully, the words "Press any key to continue" will appear, and the cmd console will be closed after pressing any key.

The above is the detailed content of How to use notepad to compile c language. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Getting Started: Installing Notepad   for BeginnersGetting Started: Installing Notepad for BeginnersApr 29, 2025 am 12:25 AM

The steps for installing and initial use of Notepad are as follows: 1) Visit notepad-plus-plus.org to download the appropriate version; 2) Double-click the installation file and install it as prompts; 3) Start Notepad, create a new file and enter text; 4) Save the file and select the file type; 5) Write and run a simple Python program, such as print("Hello,Notepad !"). Through these steps, you can start programming with Notepad smoothly.

The Home of Notepad  : Discovering Its Country of OriginThe Home of Notepad : Discovering Its Country of OriginApr 28, 2025 am 12:20 AM

Notepad originatesfromFrance,developedbyDonHo.1)DonHostartedNotepad in2003tocreateapowerful,user-friendlytexteditor.2)France'stechcommunityandtheGNUGPLlicensefacilitatedglobalcontributionstoNotepad .3)TheFrenchinfluenceisreflectedinNotepad 'seleg

Installing Notepad   on Windows: A Comprehensive TutorialInstalling Notepad on Windows: A Comprehensive TutorialApr 27, 2025 am 12:15 AM

Notepad shouldbeinstalledonWindowsforitsproductivityfeatures.1)Visittheofficialwebsiteanddownloadtheappropriateversion.2)Runtheinstallerandfollowprompts,optionallyassociatingfiletypes.3)Customizesettingsandexplorepluginspost-installation.

The Origin of Notepad  : Identifying Its Country of OriginThe Origin of Notepad : Identifying Its Country of OriginApr 26, 2025 am 12:07 AM

Notepad is a text editor born in France and developed in 2003 by Vietnamese engineer Don Ho. Reasons for its popularity include: 1. Open source and free, 2. Efficient performance, 3. Rich features, such as multi-document interfaces and plug-in systems.

Installing Notepad  : A Step-by-Step GuideInstalling Notepad : A Step-by-Step GuideApr 25, 2025 am 12:08 AM

Notepad isapowerful,customizabletexteditoridealforcodersandwriters,offeringfeatureslikesyntaxhighlightingandpluginsupport.Toinstall:1)Downloadfromtheofficialwebsite,2)Runtheinstaller,choosingyourlanguageandinstallationoptions,3)Customizepost-install

The Cost of Notepad  : What You Need to KnowThe Cost of Notepad : What You Need to KnowApr 24, 2025 am 12:06 AM

Notepad usage is accompanied by implicit costs of time, learning curve, and productivity losses, but it can be maximized by leveraging plugins, customizing workflows, and combining other tools. Using Notepad may take more time to complete tasks manually, learning its plug-in system and customization functions takes time, and simplicity may lead to productivity loss, but by installing plug-ins such as NppFTP, customizing shortcut keys and interfaces, and combining GitBash and VisualStudioCode, development efficiency can be effectively improved.

Notepad  : Free to Download and Use?Notepad : Free to Download and Use?Apr 23, 2025 am 12:05 AM

Notepad is completely free and open source. 1. It is based on Windows, developed by DonHo, and supports multiple programming languages. 2. Provides syntax highlighting, code folding and other functions, which are lightweight and have low resource consumption. 3. Through macros and plug-ins such as NppExec, tasks can be automated and external commands can be executed. 4. It is recommended to update regularly, explore community resources, and consider other editors according to your needs.

The Notepad   Installation Process: A Detailed ExplanationThe Notepad Installation Process: A Detailed ExplanationApr 22, 2025 am 12:03 AM

Installation steps of Notepad: 1. Visit the official website to download the latest stable version; 2. Run the installation file and click "Next"; 3. Agree to the license agreement; 4. Select the installation path; 5. Select whether to create a desktop shortcut and start menu folder; 6. Complete the installation and start Notepad.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools