Up

C/C++ Program with Python Script

 

A simple C/C++ program can use facilities of Python. The C/C++ program Source.cpp in Figure 1 produces random numbers and write out them into the file temp.txt. To run the Python script CheckFreq.py in Figure 1, c function system (Line 18) calls the Python script CheckFreq.py, which reads in the file temp.txt and draw a bar graph (Figure 2). Note that C/Cpp source code file Source.cpp and Python script CheckFreq.py are put in the same folder.

Figure 1

 

The bar graph in Figure 2 is drawn by matplotlib function hist (Line 20 in CheckFreq.py).

Figure 2

 

Up