Skip to main content

Running C Programs

Objectives:

Having read this section you should be able to:

1.Edit, link and run your C programs



This section is primarily aimed at the beginner who as no or little experience of using compiled languages. We cover the various stages of program development. The basic principles of this
section will apply to what ever C compiler you choose to use, the stages are nearly always the same


The Edit-Compile-Link-Execute Process:

Developing a program in a compiled language such as C requires at least four steps:

1.editing (or writing) the program
2.compiling it
3.linking it
4.executing it

We will now cover each step separately.


Editing:

You write a computer program with words and symbols that are understandable to human beings. This is the edit part of the development cycle. You type the program directly into a
window on the screen and save the resulting text as a separate file. This is often referred to as the source file (you can read it with the TYPE command in DOS or the cat command in unix).

The custom is that the text of a C program is stored in a f ile with the extension .c for C programming language


Compiling:

You cannot directly execute the source file. To run on any computer system, the source file must be translated into binary numbers understandable to the computer's Central Procesing Unit
(for example, the 80*87 microprocessor). This process produces an intermediate object file - with the extension .obj, the .obj stands for Object.



Linking:

The first question that comes to most peoples minds is Why is linking necessary? The main reason is that many compiled languages come with library rountines which can be added to your
program. Theses routines are written by the manufacturer of the compiler to perform a variety of tasks, from input/output to complicated mathematical functions. In the case of C the standard
input and output functions are contained in a library (stdio.h) so even the most basic program will require a lib rary function. After linking the file extension is .exe which are executable

files.


Executable files:

Thus the text editor produces .c source files, which go to the compiler, which produces .obj object files, which go to the linker, which produces .exe executable file. You can then run
.exe files as you can other applications, simply by typing their names at the DOS prompt or run using windows menu.


Using Microsoft C:

Edit stage:
Type program in using one of the Microsoft Windows editing packages.

Compile and link:
Select Building from Make menu. Building option allows you to both compile and link in the same option.

Execute:
Use the Run menu and select Go option.

Errors:
First error highlighted. Use Next Error from Search menu for further errors if applicable.

If you get an error message, or you find that the program doesn't work when you finally run it (at least not in the way you anticipated) you will have to go back to the source file - the .c file -
to make changes and go through the whole development process again!


Unix systems:

The University's central irix Service is a Silicon Graphics Inc. Challenge XL system which runs a Unix-like operating sysem called IRIX. The basic information to run a C program on this

system is covered in document HT.SI.05 - How To... Run C Programs On The irix Service. Although this document refers to the IRIX operating system many of the command options will
be common to all Unix systems.

On all Unix systems further help on the C compiler can be obtained from the on-line manual. Type

man cc

on your local Unix system for more information.

Please note that Unix is a case sensitive operating system and files named firstprog.c and FIRSTPROG.c are treated as two separate files on these system. By default the Unix system

compiles and links a program in one step, as follows:

cc firstprog.c

This command creates an executable file called a.out that overwrites any existing file called a.out. Executable files on Unix are run by typing their name. In this case the program is run as
follows:

a.out

To change the name of the executable file type:

cc -o firstprog.c

This produces an executable file called firstprog which is run as follows:

firstprog

Comments

Popular posts from this blog

13 websites to register your free domain

Register your Free Domain Now!! 1)  .tk Dot TK is a FREE domain registry for websites on the Internet. It has exactly the same power as other domain extensions, but it’s free! Because it’s free, millions of others have been using .TK domains since 2001 – which makes .TK powerful and very recognizable.  Your website will be like www.yourdomainname.tk . It is free for 1 year. It’s a ccTLD domain whixh having the abbreviation  Tokelau. To create a .tk domain, Visit   www.dot.tk 2) co.cc Co.cc is completely free domain which is mostly used by blogspot bloggers because of it’s easy to use DNS system. Creating a co.cc for blogger is simple ( for instructions- “click here”). Your website will be like www.yourdomainname.co.cc . To create a .co.cc domain, visit www.co.cc 3)   co.nr co.nr is too like co.cc. Your website will be like  www.yourdomainname.co.nr . You can add it for blogger also.. To create a .co.cc domain, vi...

what is LOREM ipsum and why do designers use it

What is Lorem Ipsum? Lorem Ipsum  is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now...

FIXED : Google adsense error in inserting code to blog throwing error Attribute name "async" associated with an element type "script" must be followed by the ' = ' character

Error - Asynchronous adsense code in HTML just add ='async' between async and src of your code ... let say my code for adsense is < script async src = 'http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js' ></ script > then do the following...... < script async = 'async' src = 'http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js' ></ script > notice the difference this is how you can add that error and display the google ads ..

Exception Handling in Java

Exception Handling() it is an event that stops the normal flow of execution of the program and terminates the program abnormally. Exception always occurs at runtime. There Is two type of Exception: Checked Exception.:-The exception which is checked by the compiler at the compilation time. Ex: IOException,ClassNotFoundException. Unchecked Exception: The Exception which Cant be checked by the compiler at the compilation time and directly occurs at runtime is called an unchecked Exception. Ex:NullPointerException,StringIndexOutOfBoundsException. Error: Error is the type of unchecked Exception which occurs due to programmers mistake, end-user input mistake, resource unavailability or network problem etc. OutOfMemoryError StackOverFlowError etc. 5 keywords to handle Exception: try catch finally throw throws possible combination: try-catch try-catch-catch try-catch-finally try finally try-...

how free is microsoft sql server developer edition really

Five reasons to take a chance It is free – although the commercially licensed version of SQL Server is often less expensive that other leading database products anyway, you cannot get it cheaper than for zero cost. While it may only be used for non-operational purposes, the developer edition is still a good way of trying out new functions, testing, training, and so on. It is fully loaded – it has all the same functions as the licensed SQL Server 2016 Enterprise edition, not a cut down version. This is important if you are using it to build applications that will eventually become real products or services. It is unlimited – you can deploy any number of copies on an unlimited number of devices, including virtual machines hosted on multitenant infrastructure. It is easily downgradeable – you can use the license to access SQL Server 2014 Developer Edition, without having to acquire a separate license for it. It is free – did I mention that already? Five reasons to skip this opti...

python program to Print Starting Series OF Indian Mobile Number for a State or operator or both

import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e...

SQL Server 2016 RTM full and final version available – Download it

–> Download SQL Server: To download SQL Server 2016 you can  Register and Download  the SQL Server 2016 Full or free Evaluation version (180 days) here. Or you can  Direct download  the DVD ISO file image (~2.1 GB)  SQLServer2016-x64-ENU.iso   –> Free Developer Version: Microsoft on March 2016 announced that going forward the Developer version of SQL Server any release will be free for Developers and Learning purpose.  Register and Download  the Developer version. Or you can  Directly download  the DVD ISO image (~2.1 GB):  en_sql_server_2016_developer_x64_dvd_8777069.iso This  Developer version  is meant for  development and testing  only, and  not for production environments  or for use with production data. For more info please check my  previous blog post .   –> One big Update on SSMS: From now onward SSMS i.e. SQL Server Management Studio will not be part of SQL ...

Windows 10 1703 Fall Creator update/upgrage brings NEW UI ... the fluent Ui

Microsoft is planning to implement these subtle design changes gradually. Some are already available in new updates to existing Windows 10 apps, and more will start to appear in Windows itself as Microsoft updates the operating system with the Fall Creators Update and future updates. "It's going to be a journey," says Microsoft director Aaron Woodman, noting that these design changes will appear over time in Windows and other products. On stage at Build today, Microsoft's Joe Belfiore demonstrated a number of Fluent Design changes. "You're going to see Fluent Design show up in the Windows shell, in our apps, and across devices," explains Joe Belfiore. Microsoft is focusing on light, depth, motion, material, and scale for its Fluent Design, with subtle changes that make the design feel like it's moving during interactions in Windows. An inking demo showed how Microsoft is bringing the pen experience across the entirety of Windows, allowing...

how to write a Factorial program in PROLOG.

So to Write A prolog programming . First Fire up your SWI -PROLOG software. then you will see something like this . Welcome to SWI-Prolog (threaded, 64 bits, version 7.4.2) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- _ 1. So now go to File>NEW.... and give any name to knowledge base file. I Give it factorial .pl 2.  now write the follwing fact and rules . fact(0,1) . fact(N,R):-  N>0, N1 is N-1, fact(N1,R1), R is N*R1. now press ctrl +s to save  . 3. now close this windows . 4. now in the main window goto file > Consult..... and select your factorial.pl 5. now you can type query like fact(5,X). it will return X=120. done..... here are some screen shot :...