Thursday, August 7, 2014

Notepad++ as editor for C Development


Notepad++ is a very powerful text editor. For beginners of programming, it could be an alternative to basic notepad editor available on Windows. This tutorial is specific to C development. Notepad++ can use available compilers to compile C code in integrated mode. In this tutorial, we will make use of Minimalist GNU for Windows (MinGW), a complete Open Source programming tool set. The first step will be to download and install Notepad++ available at:
http://notepad-plus-plus.org/

Second step will be to download and install MinGW available at:
 http://www.mingw.org/.

Or specifically, we used following link:
http://cznic.dl.sourceforge.net/project/mingw/Installer/mingw-get-setup.exe

Execute the downloaded executable and select the options as shown in figure below:



After installation, please make sure that the bin folder of the MinGW is added to Path variable in system variables as shown in figure below:



Similarly, install the Notepad++. After installation, open the editor. You can also select the language for your source code file using Language menu or Notepad++ will automatically detect it using the extension of your source file, which in our case is .c


To use Notepad++ for integrated compilation and execution of C Source Code on command prompt. Will need a Plugin with name NppExec. To open Plugin Manager, use Plugins -> Plugin Manager -> Show Plugin Manager menu. Select the NppExec from the list of plugins as shown in figure below and install it.


Now you are ready to set the plugin for integrated compilation and execution of the code. Write the source code that you want to compile and execute. Use Plugins -> NppExec -> Execute menu as show in figure below:


Add following script in the opened dialog box:

NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
cmd /c del "$(NAME_PART).exe"
gcc "$(FILE_NAME)" -o $(NAME_PART)
NPP_RUN $(NAME_PART)

Also shown in figure below:



As you press OK. The program will be compiled and executed. A console will appear below the text window, which will display the compilation process and any compilation errors, if may occur. If compilation completes successfully, as separate command prompt window will open and will execute you program. However, you should be careful to check if program compiled successfully or not. Above given script will execute the old program file even when compilation fails.


Two relevant online resources used in making this tutorial are:

Compile with Notepad++ (Any language)
http://windowsbro.blogspot.com/2012/10/compile-with-notepad-any-language.html

How to compile C++ code in Notepad++ with gcc/g++
http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html

Happy C programming with Notepad++

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.