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
notepad文件太大打不开怎么办notepad文件太大打不开怎么办Apr 08, 2024 am 03:15 AM

当 Notepad 文件过大时,可以尝试以下解决方案:使用其他文本编辑器,如 Sublime Text,因为他们没有文件大小限制。将文件分割成较小的部分。通过注册表编辑器启用大文件支持。尝试使用记事本++、WordPad 或 Microsoft Word 等替代方法打开文件。压缩文件,然后使用存档工具打开。

notepad++mac怎么安装notepad++mac怎么安装Apr 08, 2024 am 12:45 AM

在 Mac 上安装 Notepad++ 的步骤:下载 DMG 文件:从官方网站下载最新的 DMG 文件。安装 DMG 文件:打开 DMG 文件并将 Notepad++ 图标拖到“应用程序”文件夹中。启动 Notepad++:从“应用程序”文件夹中启动程序。授予完全磁盘访问权限(可选):如果提示,请授予 Notepad++ 完全磁盘访问权限。自定义设置(可选):通过“首选项”菜单调整设置以符合个人喜好。

notepad++怎么转换编码notepad++怎么转换编码Apr 08, 2024 am 02:12 AM

摘要:使用 Notepad++ 转换编码格式需遵循以下步骤:打开文件检查当前编码选择新编码确认转换保存文件

notepad的换行符怎么去掉notepad的换行符怎么去掉Apr 08, 2024 am 02:42 AM

要去除 Notepad 中的换行符,可以按照以下步骤操作:打开 Notepad。打开要编辑的文件。查找并替换换行符。单击“替换全部”。保存文件。

notepad怎么让文本列对齐notepad怎么让文本列对齐Apr 08, 2024 am 01:00 AM

可使用三种方法在 Notepad 中实现文本列对齐:1、使用制表符;2、使用空格并手动调整;3、使用第三方工具(如 Notepad++、Sublime Text)提供自动对齐功能。

notepad++乱码怎么弄notepad++乱码怎么弄Apr 08, 2024 am 02:09 AM

Notepad++乱码问题可以通过以下步骤解决:检查编码是否匹配文件内容转换文本格式为UTF-8或ANSI安装“编码转换”插件并尝试不同编码选项手动更改编码声明行(如果文件存在)重新启动Notepad++

notepad.exe未响应怎么办notepad.exe未响应怎么办Apr 08, 2024 am 03:12 AM

Notepad.exe 未响应的解决方法:1. 强制退出进程;2. 检查并清除恶意软件;3. 重置 Notepad.exe;4. 更新或重新安装 Notepad.exe;5. 运行系统文件检查器;6. 若以上方法无效,请联系 Microsoft 支持。

在notepad++怎么把换行去掉在notepad++怎么把换行去掉Apr 08, 2024 am 02:48 AM

在 Notepad++ 中删除换行符的方法:1. 打开“编辑”菜单;2. 选择“替换”;3. 在“查找”字段中输入 \n;4. 在“替换为”字段中留空;5. 选中“替换全部”按钮。注意:操作前备份文件,删除操作无法撤消。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),