How to Conjure a Terminal Window in C Programming
Whether you’re using Windows, Mac OS X, Linux, or a Unix variant, you can still bring forth a terminal window with C programming, in which you can witness the awesome starkness of the command prompt. It’s a text-only environment.
How to start a terminal window
Below you can see the Windows command prompt as well as the Terminal window on the Macintosh. Linux and Unix systems feature a terminal window similar to the one the Mac uses.
To open a command prompt in Windows, follow these steps:
Press the Win+R key combination.
The Run dialog box appears.
Type cmd and click the OK button.
The command prompt window appears.
To open a terminal window on the Macintosh, follow these steps:
Switch to the Finder app; click the desktop.
Press Command+Shift+U to view the Utilities folder.
Open the Terminal program.
In Linux and Unix, running a variant of the X Window system, open a terminal window by running the Xterm (or similar) program. Often, you find a terminal window icon or shortcut easily accessible from the desktop.
To close the command prompt or terminal window, type the exit command and press the Enter key.
How to run code in Text mode
In Text mode, Code::Blocks shows you a preview window, but you can also run your programs directly through the command prompt or terminal window. The trick is finding your code, which requires a little command-prompt acumen.
If you’re using an integrated development environment other than Code::Blocks or you’re compiling directly at the command prompt, you may know best how to find your code. Otherwise, the demo programs should be rather easy to find. Heed these directions:
Open a command prompt or terminal window.
The command prompt or terminal window opens to your User Profile or Home folder. This folder doesn’t contain your C programs, so you need to switch or change to another folder. (You can run programs without switching folders, but switching is easier.)
Use the cd, change directory, command to switch to the folder you created for storing projects.
Type cd prog/c/begc4d and press the Enter key.
Type a space after the cd command and then type the pathname exactly as just listed.
Code::Blocks creates project folders for each program you’ve created. The project folder is named after the project you’ve saved. To run the program that’s created, you must change to the project’s bin folder:
Type cd ex1409/bin/release and press the Enter key.
The current directory now contains the executable program file for your project.
To run the project, type its name at the command prompt.
For project ex1409 in Windows, type ex1409 and press Enter. On the Mac or in Linux or Unix, you have to focus the operating system’s attention on the current directory. Type ./ex1409 and press the Enter key.
These steps can be followed to run any program you’ve created at the command prompt. Simply substitute the project and program’s name instead of ex1409.