A Tutorial on Getting Started with Ch and Crimson Editor as IDE

Table of Contents


Ch is an embeddable C/C++ interpreter for cross-platform scripting, shell programming, 2D/3D plotting, numerical computing, and embedded scripting. Crimson Editor is a professional source code editor for Windows. It can be used as an Integratted Development Environment (IDE) to run C/Ch/C++ scripts in Ch. In this brief tutorial, Crimson Editor will be configured as an IDE to run C/Ch/C++ scripts/programs. Three examples are given to show how to run Ch from Crimson Editor, and how to take input from Crimson Editor that is then passed to Ch, and how to plot using Ch Professional Edition.

Ch can be downloaded from http://www.softintegration.com

Crimson Editor can be downloaded from http://www.crimsoneditor.com

Configuring Crimson Editor For Ch

After launching Crimson editor, under the Tools category, select "Conf. User Tools..." as shown in Figure 1.

Figure 1: Tools drop down menu

Select an empty slot and fill in the following arguments as shown in Figure 2.
- Menu Text: Execute C/Ch/C++ Script
- Command: C:\ch\bin\ch.exe
- Argument: -u "$(FileName)"
- Initial dir: $(FileDir)
- Hot key: F5
- Capture output: Yes
- Save before execute: Yes

Please make sure do not add any additional spaces ahead of the above arguments, i.e., use "ch.exe", not use " ch.exe". " ch.exe" will not be able to execute the code.

Figure 2: Configuration parameters

Using Ch under Crinsom Editor - Example 1

This example will show how to run a C/Ch/C++ program/script after it has been typed into Crimson Editor. Type in the code as shown in Figure 3. During execution, this code should display the output "hello world".

Figure 3: First example code

To save the program, select "Save" from the "File" drop down menu as shown in Figure 4. Then name your program as shown in Figure 5. Finally, click the "Save" button.

Figure 4: File drop down menu

Figure 5: Save window

By default setup, the program will be saved before it is executed. The execution of the file using Ch under Crimson Editor can be accomplished through 2 different methods. The first method, as shown in Figure 6, is to choose the "Execute C/Ch/C++ Script" from the "Tools" drop down menu. The second method is to hit the "F5" key on your keyboard since the "F5" key was setup as a shortcut key for the execution of Ch under Crimson Editor.

The output of both methods should be the same. The output from a program executed with Ch under Crimson Editor is shown in the Output box, normally located below the input frame as shown in Figure 7. As can be seen, the output shows "hello world" as desired.

Figure 6: Using the tools menu for program execution

Figure 7: Output of the first example

Using Ch with Input under Crinsom Editor - Example 2

This example will show how to run a C/Ch/C++ program/script that requires the user to input data. Type in the code as shown in Figure 8. During execution, this code should ask the user to "Please intput a number" and then cause the system to output "Yout input number is" and the number that the user inputted.

Figure 8: Input example code

During the exection of the program, the user will be prompted to input a number as shown in Figure 9. The user then must type in a number in the designated input location below the output. Here, the number "56", circled in red, was inputted.

The desired output as shown in Figure 10 is displayed.

Figure 9: Inputting data into Crimson Editor that is then passed to Ch

Figure 10: Output of the second example

Plotting with Ch under Crimson Editor- Example 3

This example will show how to run a C/Ch/C++ program/script that creates a plot. Type in the code as shown in Figure 11. During execution, this code should create a new screen with a plot as shown in Figure 12. The plotting functions are avaiable in Ch Professional Edition. This example utilized computation arrays to store the data used for plotting.

Figure 11: Plot example code

Figure 12: Plot example output