Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
🔒 NordVPN Premium – 3 Months
hrdilshan
Updated:
Yesterday at 8:29 PM
🚀 Microsoft Office 365 Pro Plus – Lifetime Access! 🚀
hrdilshan
Updated:
Yesterday at 8:28 PM
Linkedin Premium Business / Careere /Sales Navigator - 1/2/3/6/9/12 Months - Reddem Link
hrdilshan
Updated:
Yesterday at 8:27 PM
Colombo
YEYE 3 in 1 Instant Coffee Mix 50 Sachet
Romeshka
Updated:
Wednesday at 12:16 AM
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Jul 3, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Lesson 02 : C Programming
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="x-pert" data-source="post: 641201" data-attributes="member: 837"><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Hi guys... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">This is the second lesson of C Programming. <a href="http://www.elakiri.com/forum/showthread.php?t=35788" target="_blank">If you haven’t read the first one please read it before reading this. Coz in the first one I have mentioned what is programming kinda thing... </a></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">In this second lesson I’m gonna tell you how to write and compile the first C program. Dont worry about the syntax and rules and all the things... Just try to write it and compile and run... Eventually I will tell the meaning of each and every line and stuff like that... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">You need to have a compiler to compile the program. Compiler changes the source code written in C language by you to a language understandable by the computer. So after you write a C source code, you have to compile it, then only you can run the program in a computer.</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">There are two main kinds of compilers: 1) for UNIX environment 2) for MS DOS/Windows environment.</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>UNIX </strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">You will have to use a command line compiler such as UNIX compiler (cc) or Free Software foundation’s compiler (gcc)</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>DOS/ Windows</strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">You can use Turbo C++. Borland C++ or Micro$oft visual C++ compilers</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">I’m not gonna talk about UNIX compiling method, as most of the EK members are using windows as I guess.... But if you wanna know that method pls let me know. I can put it too. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">So lets see how to create and compile and run a C program in Windows environment... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">First open a notepad and type the following command. <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /> </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">#include <stdio.h></span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">int main()</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">{</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">printf("Hello World\n");</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">return (0);</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">}</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Dont worry guys... Will explain the codings later. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Then save the file as hello.c</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Save it in the C:/ directory for the moment. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>Compiling with Borland C++ compiler.</strong>Go to start->run->cmd</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Or open the command prompt. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Type </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">C:> tcc -ml -v -N -w -ehello hello.c</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>tcc </strong>means Turbo C++ compiler</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>-ml </strong>means that we are using the large memory model (Dont think about it now)</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>-v </strong>tells the compiler to put the debugging info on the program</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>-N</strong> turns on the stack checking</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>-w</strong> turns on the wrnings</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>-ehello hello.c</strong> tells the compiler to build a program called <strong>hello</strong> from the <strong>hello.c </strong>source code. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>Using the Borland C++ compiler</strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Same as above just type </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">C:> bcc -ml -v -N -w -ehello hello.c</span></span>(tcc changes to bcc)</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong></strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>Using Micro$oft visual C++ compiler</strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Same procedure but type </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">C:> cl /AL /Zi /W1 hello.c</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>/AL</strong> tells the compiler to use the large memory model</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>/Zi</strong> turns on the debugging</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>/W1</strong> turns on the warnings</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">To execute the program you just wrote and compiled, you have to type </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">% hello </span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">With any compiler, you can use this command to execute your program. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Then <strong>Hello World </strong>should appear on your screen. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Now, If you save your program in a different location lets say in a folder called <strong>ElaKiri</strong> in your C:/ drive, </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Then when you are compiling the program you should first go to that directory</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Ex: <span style="font-family: 'Courier New'"><span style="font-size: 15px"><strong>C:/ElaKiri </strong>> bcc ehello hello.c </span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Thats why I told you to save the program in C for the first time.. <img src="/styles/default/xenforo/smilies/default/wink.gif" class="smilie" loading="lazy" alt=";)" title="Wink ;)" data-shortname=";)" /></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">ElaKiri... Now you have done the programming in the hard way... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">There is an easy way <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> <img src="/styles/default/xenforo/smilies/default/lol.gif" class="smilie" loading="lazy" alt=":lol:" title="LOL :lol:" data-shortname=":lol:" /> <img src="/styles/default/xenforo/smilies/default/cool.gif" class="smilie" loading="lazy" alt=":cool:" title="Cool :cool:" data-shortname=":cool:" /></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Always better to learn the hard way. (In UNIX thats the easy way)</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">If you have the softwares (Not just the compilers but the IDEs) such as <strong>Visual Studio 6, Turbo C++</strong> or whatever C or C++ programming software, then you can easily type the source code in there and execute it... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">I ll tell only Micro$oft’s way.... which is bit easy I beleive. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Open Visual studio.</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Go to Project->new project</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Create a new c application. (Actually I haven’t used it for 3 years now. So can’t remember the exact path. Just create a new project some way or the other.) </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Kauru hari danna ekkenek innawanam kiyanna... habai loku case ekak nemei... easy podi wadak... Kohoma hari new project ekak patan arganna thiyanne.... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Project type will be QuickWin application. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">After creating a new project type the source code</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">#include <stdio.h></span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">int main()</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">{</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">printf("Hello World\n");</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">return (0);</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><span style="font-size: 15px">}</span></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Go to File->save and save the project which you have already created. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Then go to Project->build and it will build the source code</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Then you can start/run the program. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Thats it for now... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Next time we’ll review some source codes.. So that you will get a flavour of C <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /> </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><em>Source : Oualline, C. Practical C Programming, 3rd edt., O’reilly Publications</em></span></span></p></blockquote><p></p>
[QUOTE="x-pert, post: 641201, member: 837"] [FONT="Arial"][SIZE="3"]Hi guys... This is the second lesson of C Programming. [URL="http://www.elakiri.com/forum/showthread.php?t=35788"]If you haven’t read the first one please read it before reading this. Coz in the first one I have mentioned what is programming kinda thing... [/URL] In this second lesson I’m gonna tell you how to write and compile the first C program. Dont worry about the syntax and rules and all the things... Just try to write it and compile and run... Eventually I will tell the meaning of each and every line and stuff like that... You need to have a compiler to compile the program. Compiler changes the source code written in C language by you to a language understandable by the computer. So after you write a C source code, you have to compile it, then only you can run the program in a computer. There are two main kinds of compilers: 1) for UNIX environment 2) for MS DOS/Windows environment. [B]UNIX [/B] You will have to use a command line compiler such as UNIX compiler (cc) or Free Software foundation’s compiler (gcc) [B]DOS/ Windows[/B] You can use Turbo C++. Borland C++ or Micro$oft visual C++ compilers I’m not gonna talk about UNIX compiling method, as most of the EK members are using windows as I guess.... But if you wanna know that method pls let me know. I can put it too. So lets see how to create and compile and run a C program in Windows environment... First open a notepad and type the following command. :) [FONT="Courier New"][SIZE="4"]#include <stdio.h> int main() { printf("Hello World\n"); return (0); }[/SIZE][/FONT] Dont worry guys... Will explain the codings later. Then save the file as hello.c Save it in the C:/ directory for the moment. [B]Compiling with Borland C++ compiler.[/B]Go to start->run->cmd Or open the command prompt. Type [FONT="Courier New"][SIZE="4"]C:> tcc -ml -v -N -w -ehello hello.c[/SIZE][/FONT] [B]tcc [/B]means Turbo C++ compiler [B]-ml [/B]means that we are using the large memory model (Dont think about it now) [B]-v [/B]tells the compiler to put the debugging info on the program [B]-N[/B] turns on the stack checking [B]-w[/B] turns on the wrnings [B]-ehello hello.c[/B] tells the compiler to build a program called [B]hello[/B] from the [B]hello.c [/B]source code. [B]Using the Borland C++ compiler[/B] Same as above just type [FONT="Courier New"][SIZE="4"]C:> bcc -ml -v -N -w -ehello hello.c[/SIZE][/FONT](tcc changes to bcc) [B] Using Micro$oft visual C++ compiler[/B] Same procedure but type [FONT="Courier New"][SIZE="4"]C:> cl /AL /Zi /W1 hello.c[/SIZE][/FONT] [B]/AL[/B] tells the compiler to use the large memory model [B]/Zi[/B] turns on the debugging [B]/W1[/B] turns on the warnings To execute the program you just wrote and compiled, you have to type [FONT="Courier New"][SIZE="4"]% hello [/SIZE][/FONT] With any compiler, you can use this command to execute your program. Then [B]Hello World [/B]should appear on your screen. Now, If you save your program in a different location lets say in a folder called [B]ElaKiri[/B] in your C:/ drive, Then when you are compiling the program you should first go to that directory Ex: [FONT="Courier New"][SIZE="4"][B]C:/ElaKiri [/B]> bcc ehello hello.c [/SIZE][/FONT] Thats why I told you to save the program in C for the first time.. ;) ElaKiri... Now you have done the programming in the hard way... There is an easy way :P :P :P :P :lol: :cool: Always better to learn the hard way. (In UNIX thats the easy way) If you have the softwares (Not just the compilers but the IDEs) such as [B]Visual Studio 6, Turbo C++[/B] or whatever C or C++ programming software, then you can easily type the source code in there and execute it... I ll tell only Micro$oft’s way.... which is bit easy I beleive. Open Visual studio. Go to Project->new project Create a new c application. (Actually I haven’t used it for 3 years now. So can’t remember the exact path. Just create a new project some way or the other.) Kauru hari danna ekkenek innawanam kiyanna... habai loku case ekak nemei... easy podi wadak... Kohoma hari new project ekak patan arganna thiyanne.... Project type will be QuickWin application. After creating a new project type the source code [FONT="Courier New"][SIZE="4"]#include <stdio.h> int main() { printf("Hello World\n"); return (0); }[/SIZE][/FONT] Go to File->save and save the project which you have already created. Then go to Project->build and it will build the source code Then you can start/run the program. Thats it for now... Next time we’ll review some source codes.. So that you will get a flavour of C :D [I]Source : Oualline, C. Practical C Programming, 3rd edt., O’reilly Publications[/I][/SIZE][/FONT] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom