How to run C program without an IDE?

In our last tutorial, we discussed the C programming language and write our first Hello World program but we have to run it to get the desired output.

1. IDE for C Programming

In order to run any C program, a system needs to fulfill certain requirements. Before you start coding in C, you need a compiler that interprets the high-level language into machine code that a computer can understand.

Also, a text editor is needed in order to write the code. IDEs (Integrated Development Environment) mostly come with both these features which make it easier because the installation of just one software is needed to write the code and run it.

The most popular IDEs for C programming are Code::Blocks, TurboC, Netbeans IDE, Eclipse CDT, etc. IDEs are really user-friendly but while learning a new language, details should be kept in mind. Running a C program with the help of a text editor, compiler, and command prompt is really helpful in this case as we have to write complete code and there is no pre-baked code that is generally made available by an IDE.

In this tutorial, we will go through the process involved in order to run a C program without using an IDE.

The things that one needs to do so are :

  • A text editor (Notepad++, sublime text, etc)
  • A compiler (TurboC compiler, Cygwin B20,etc)
  • Command prompt which is already available in windows.

2. Steps to run a C program without an IDE

The first step involves the installation of a text editor and a compiler. The text editor used in this tutorial is Notepad++ and the compiler is Cygwin B20.

Step 1: After the installation of the compiler, open “C:/” drive of your computer and go to the file named cynusfollowed by cygwin-b20 where you will find another file H-i586-cygwin32(refer to image).

capture2
capture3

Step 2: Go to the bin folder inside the H-i586-cygwin32 and copy the path. To copy the path either click on the address bar  and copy using keyboard shortcuts or right-click on the bin on the address bar and click on Copy address.(refer to image)

Step 3: Right-click on This PC and go to Properties .Then click on Advanced system settings . Click on Environment Variables  (refer to image).

capture

Step 4: Click on the New button. Another dialogue box with the name New User Variable will pop up. In the Variable Name section type in PATH and in the Variable Value section paste the address which you copied in step 2(See image below). Click OK thrice.

If PATH variable already exists in you environment variables then there are two ways to update the environment variable-

  •  You can add the copied path at the end of existing PATH value separated by a ‘;’ (For example if existing value is “value1” and you have to add “value2” to the existing value the the new value is “value1;value2”)
  • You can create a new variable(let’s say cygwin) and add it to the existing PATH variable in a way(if “value1” is existing value then new value will be “value1;%cygwin%”)
capture4

Step 5: With the path all set up let’s get to the coding part. Type in your code in the text editor of your choice(Here Notepad++). Here I have used the “Hello World!” program used in the previous tutorial. Save it with a .c extension (Eg: Hello.c) in your desired location.

Step 6: Open a command prompt and change the directory to the address where you saved your program. To do so type in >cd address (here >cd C:\hello)and press enter. In the next line type in >gcc filename.c(Here >gcc hello.c) and press enter . If there is no error type >a.exe and press enter. The output shall be displayed as follows :(see image)

capture5

And here we have our output.


Helpful Links

Please follow C Programming tutorials or the menu in the sidebar for the complete tutorial series.

Also for the example C programs please refer to C Programming Examples.

All examples are hosted on Github.

An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding

Do not forget to share and Subscribe.

Happy coding!! 😊

Recommended -

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x