Skip to main content

Structure of C Programs

Objectives:

Having completed this section you should know about:

1.C's character set
2.C's keywords
3.the general structure of a C program
4.that all C statement must end in a ;
5.that C is a free format language
6.all C programs us header files that contain standard library functions.


C's Character Set:

C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows:

A - Z
a -z
0 - 9
space . , : ; ' $ "
# % & ! _ {} [] () < > |
+ - / * =

The use of most of this set of characters will be dicussed throughout the course.


The form of a C Program:

All C programs will consist of at least one function, but it is usual (when your experience grows) to write a C program that comprises several functions. The only function that has to be
present is the function called main. For more advanced programs the main function will act as a controling function calling other functions in their turn to do the dirty work! The main

function is the first function that is called when your program executes.

C makes use of only 32 keywords which combine with the formal syntax to the form the C programming language. Note that all keywords are written in lower case - C, like UNIX, uses
upper and lowercase text to mean different things. If you are not sure what to use then always use lowercase text in writing your C programs. A keyword may not be used for any other
purposes. For example, you cannot have a variable called auto.

The layout of C Programs:

The general form of a C program is as follows (don't worry about what everything means at the moment - things will be explained later):

preprocessor directives
global declarations
main()
{
local variables to function main ;
statements associated with function main ;
}
f1()
{
local variables to function 1 ;
statements associated with function 1 ;
}
f2()
{
local variables to function f2 ;
statements associated with function 2 ;

}
.
.
.
etc

Note the use of the bracket set () and {}. () are used in conjunction with function names whereas {} are used as to delimit the C statements that are associated with that function. Also note
the semicolon - yes it is there, but you might have missed it! a semicolon (;) is used to terminate C statements. C is a free format language and long statements can be continued, without
truncation, onto the next line. The semicolon informs the C compiler that the end of the statement has been reached. Free format also means that you can add as many spaces as you like to

improve the look of your programs.

A very common mistake made by everyone, who is new to the C programming language, is to miss off the semicolon. The C compiler will concatinate the various lines of the program
together and then tries to understand them - which it will not be able to do. The error message produced by the compiler will relate to a line of you program which could be some distance
from the initial mistake.


Preprocessor Directives:

C is a small language but provides the programmer with all the tools to be able to write powerful programs. Some people don't like C because it is too primitive! Look again at the set of

keywords that comprises the C language and see if you can find a command that allows you to print to the computer's screen the result of, say, a simple calculation. Don't look too hard
because it dosen't exist.

It would be very tedious, for all of us, if everytime we wanted to communicate with the computer we all had to write our own output functions. Fortunately, we do not have to. C uses
libraries of standard functions which are included when we build our programs. For the novice C programmer one of the many questions always asked is does a function already exist for

what I want to do? Only experience will help here but we do include a function listing as part of this course.

All programs you will write will need to communicate to the outside world - I don't think I can think of a program that doesn't need to tell someone an answer. So all our C programs will
need at least one of C's standard libraries which deals with standard inputting and outputting of data. This library is called stdin.h and it is declared in our programs before the main

function. The .h extension indicates that this is a header file.

I have already mentioned that C is a free format language and that you can layout your programs how you want to using as much white space as you like. The only exception are statements
associated with the preprocessor.

All preprocessor directives begin with a # and the must start in the first column. The commonest directive to all C programs is:

#include

Note the use of the angle brackets (< and >) around the header's name. These indicate that the header file is to be looked for on the system disk which stores the rest of the C program

application. Some text books will show the above statement as follows:

#include "stdio.h"

The double quotes indicate that the current working directory should be searched for the required header file. This will be true when you write your own header files but the standard header
files should always have the angle brackets around them.

NOTE: just to keep you on your toes - preprocessor statements, such as include, DO NOT use semi-colons as delimiters! But don't forget the # must be in the first column.

Thats enough background to C programs - lets get on with our first program which will start to bring together some of the ideas outlined above.

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...

Binary Search Tree in C++( dynamic memory based )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 #include<bits/stdc++.h> using namespace std; struct bst { int val; bst * left, * right; }; bst * root = nullptr; void srch ( int num,bst * head) { if (head == nullptr){ cout << " \n Number is not present \a " << endl; return ; } if (head -> val == num) { cout << " \n Number is present \n\a " ; return ; } else { if (num < head -> val) srch(num,head -> left); else srch(num,head -> right); ...

Binary Search Tree in Java implementation (reference based, dynamic memory)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 import java.util.Scanner ; class BST { static BST . Node root = null ; public void insert ( int num ) { if ( root == null ) { root = new BST . Node ( num ); } else { // root node is not empty BST . Node temp = root ; while ( temp != null ) { if ( num <= temp . getVal ()) { if ( temp . getLeft () != null ) temp = temp . getLeft (); ...

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...

Track Lost Android Phone and Tablet

1. Use the IMEI Number Every Android phone carries a unique IMEI number. It will be printed at the back of your device. If you are unable to find the number, you have to launch your phone app and dial the number *#06#. This will give you the IMEI number of your phone. Store this number in a safe place so that it helps you in locating your phone when it is lost 2 Android Device Manager Google has recently released a new locator feature for Android gadgets called Android Device Manager, which helps its users locate their lost or stolen phones and tablets. It functions in the same way as Lookout and Samsung’s “Find My Mobile”. Here’s how to use Android Device Manager. Go to the Google Settings app, then select Android device manager. By default, the locator feature is activated but to activate remote data wipe, select the box next to “Allow remote factory reset”, then select “activate”. To use this feature, open the site https://www.google.com/android/devicemanager and sig...

DOWNLOAD ADVANCED INSTALLER

DOWNLOAD FEATURES JAVA LICENSING PURCHASE SUPPORT FORUMS Caphyon Advanced Installer Advanced Installer The power of Windows Installer made easy Buy Download .MSI installs in Minutes Advanced Installers deploy products on millions of computers worldwide Powerful and easy to use  Windows Installer  authoring tool. Install, update and configure your products  safely, securely  and reliably . Freeware Windows Installer Free Installer Trial With Advanced Installer, packaging and deploying SourceTree is now just a simple part of our development process. We can focus our efforts on building new features in SourceTree and improving existing ones so that SourceTree becomes the best Windows interface to Git source repositories. Steve Streeting , Lead developer of SourceTree at  Atlassian Full story Windows Installer Software Windows Installer Software Windows Installer Software Windows Installer Software Wind...

Download pocket tank delux with 295 weapons free total 295 weapons version 1.6

Download Pocket Tanks Deluxe Full Version Free With 295 Weapons Pack | Size: 30MB UPDATED 2019 /19/april Description: Pocket Tanks is a 1-2 player computer game for Windows and Mac OS X, created by Blitwise Productions, developer of Super DX-Ball and Neon Wars. Adapted from Michael Welch's earlier Amiga game Scorched Tanks, this newer version features modified physics, dozens of weapons ranging from simple explosive shells to homing missiles, and the ability to move the tank. It supports several expansion packs. At the moment, players can have up to 295 different weapons total. Pocket Tanks is often abbreviated as PTanks. Have Fun! NOTE: FILE NAME IS SCRAMBLED FOR AVOIDING HARD DETECTION & FILE TAKEN DOWN . How to Play: Best with 2 players on the same computer at school or at work. UPDATED LINK https://mirr.re/d/u1Y https://nl26.seedr.cc/ff_get/447027537/ptd16.295.exe?st=lUp-PbRp4YOwToHIOGwStQ&e=1555747979 http://www.uploadmagnet.com/7gfzhbyfe...

Streamlining Java Web Application Deployment with React WAR Generator

In the ever-evolving world of web development, managing builds and deployments can often be cumbersome and error-prone. Today, we're excited to introduce a tool designed to simplify and streamline this process: the React WAR Generator . What is the React WAR Generator? The React WAR Generator is a Python-based tool that automates the creation of WAR (Web Application Archive) files for Java web applications. It caters specifically to frontend projects built with React or similar frameworks, making it easier to package and deploy your web applications to a Tomcat server. Key Features Profile-Based Builds : With support for multiple profiles ( dev , test , prod , default ), you can build your application according to different environments and configurations. Version File Generation : Optionally generate a version file that integrates versioning information directly into your TypeScript files, ensuring your build versions are always up-to-date. Tomcat Deployment : Simplify your deploy...

how to Send a Confirmation Email Upon Form Submission-Woofoo

When someone successfully submits an entry, you can automatically send them a confirmation email to let them know. You can customize the email to include any follow-up info you'd like, and you can choose to include a copy of their entry in the email as well. To set up confirmation emails in Form Settings: Log in and go to  Forms . Hover over  Edit  next to the form you want to edit. Choose  Edit form . Click the  Form Settings  tab. Under Confirmation Options, select  Send Confirmation Email to User . From the  Send To  dropdown, select an Email field from your form. We'll send the confirmation email to the email address the person filling out your form entered into this field. If the dropdown says "No Email Fields Found", add an  Email  field to your form. In the  Reply To  textbox, enter the reply-to email—if someone replies to their confirmation email, this is the email address that their reply will be s...

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-...