open source magazine
DESCRIPTION
A magazine on open sourceTRANSCRIPT
Fiat Lux! 02/2010
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Welcome to the first Fiat Lux!
The Editor
Here begins the first edition of Fiat Lux, the magazine of
the Free Software Cell of Government Engineering
College, Bartonhill. Like all Free Software projects this
magazine has been a labor of collaboration and it would
continue to remain so. All articles were provided
voluntarily by our members. In fact we've received more
articles than our modest page limit of 20 would allow
(they will be in the next issue). If you have an article
relevant to this magazine be assured that it has a spot in
here.
Before going into further details about this magazine lets
demystify what this Free Software Cell really is. The
Free Software Cell of our college is a volunteer
organization with members from all branches and all
semesters. As it is clear from the name, we are all about
Free/Open Source Software (FOSS) . If you are
wondering how to join the Cell you'll be happy to know
that if you show up at any of our meetings you are one of
us :-)
The goal of this magazine is to provide a platform for
Free/Open Source enthusiasts to learn from one
another. The magazine hopes to provide content
relevant to the scope of our various branches. Our
working philosophy is that everyone of us has something
to teach and something to learn from one another . This
issue has been intended as a basic stepping stone into
the various goings on in the world of FOSS. So if you
were expecting a bit more, kindly be patient, you'll get
what you are looking for in a later issue. Let us remind
you once again that this is a collaborative work,
feedback is always welcome.
WE would like to mention all those who have helped,
participated and guided this small endeavor. First and
foremost thanks goes to Renjith Sir ( Mr. Renjith S
Kumar, Lecturer, ME ), who is the guide and guardian of
the FOSS cell. Further thanks goes to our Principal Dr.
Geetha K. P. for giving us permission and support to
start this magazine. Further, I'd like to thank all the
members of the cell for the passion and commitment
they have shown in their contributions in all stages from
planning to design.
We're waiting for your criticisms, and hopefully some
complements :-)
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
What it means to be free
Vidya S
Vani S Krishna
Most software that you buy or download comes in the compiled
ready-to-run version. ‘Compiled’ means that the actual program
code that the developer created, known as the source code,
has run through a special program called a compiler that
translates the source code into a form that the computer can
understand. It is extremely difficult to modify the compiled
version of most applications and nearly impossible to see
exactly how the developer created different parts of the
program. Most commercial software manufacturers see this as
an advantage that keeps other companies from copying their
code and using it.
Open source software is quite different. The source code is
included with the compiled version and modification or
customization is actually possible. The software developers who
support the open source concept believe that by allowing
access to the source code, the application will be more useful
and error-free over the long term.
It is a common mistake to think of open source and free
software as one and the same. The difference can be
summarized in statement “all free software is open source but
not all open source software is free software”. The term free
here is meant as a reference to freedom and not price. In fact
there are many proprietary software that are technically open
source (Java is a good example of this).
FREE SOFTWARE
Free software is a matter of the users' freedom to run, copy,
distribute, study, change and improve the software. More
precisely, it refers to four kinds of freedom, for the users of the
software
• The freedom to run the program, for any purpose
(freedom 0).
• The freedom to study how the program works, and
adapt it to your needs (freedom 1). Access to the
source code is a precondition for this.
• The freedom to redistribute copies so you can help
your neighbor (freedom 2).
• The freedom to improve the program, and release
your improvements to the public, so that the whole
community benefits (freedom 3). Access to the
source code is a precondition for this.
PROPRIETARY SOFTWARE
The term "proprietary software" is often used to mean computer
software which is not free. Terminology for forms of software
licensing is not fully standardized and can be controversial. A
literal meaning of "proprietary" in relation to software is that it
has a copyright owner who can exercise control over what users
can do with the software. However, the term is commonly used
in a narrower sense to describe software with restrictions on
use or private modification, or with restrictions judged to be
excessive on copying or publishing of modified or unmodified
versions. These restrictions are placed on it by one of its
proprietors. In this sense it is also known as "non-free software"
and is the opposite of free software, generally speaking.
A related term is closed-source software which usually
describes software whose source code is not published, in
contrast with "open source". While most proprietary software is
closed-source, source-available proprietary software also exists.
SHAREWARE AND FREEWARE
Shareware is software that is distributed free on a trial basis
with the understanding that the user may need or want to pay
for it later. Some software developers offer a shareware version
of their program with a built-in expiration date (after 30 days, the
user can no longer get access to the program). Other
shareware is offered with certain capabilities disabled as an
enticement to buy the complete version of the program.
Shareware is sometimes confused with freeware. Like free
software, freeware is free in the economic sense of the word but
like shareware, freeware program code is proprietary and the
creator retains the copyright. Like shareware, freeware is
software you can download, pass around, and distribute without
any initial payment. However, the great part about freeware is
that you never have to pay for it. No 30 day limit, no demo
versions, no disabled features it's totally free. Things like minor
program updates and small games are commonly distributed as
freeware. Though freeware does not cost anything, it is still
copyrighted, so other people can't market the software as their
own.
SOFTWARE LICENCE
We all click on that button that says “Accept” while installing a
software. It is actually something called an end user agreement
to which we have just agreed without even reading the
agreement. This agreement is a form of what is called a
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
software license. The license is a legally valid agreement that
the user of the software agrees to abide by.
You may now be thinking that a license is something that is
found in proprietary software alone. Actually all free software
comes with a license to which we have to agree. It may be any
one of the many licenses around.
CREATIVE COMMONS LICENSE
Creative Commons (CC) is a nonprofit organization
headquartered in San Francisco, California, United States
devoted to expanding the range of creative works available for
others to build upon legally and to share. The organization has
released several copyright licenses known as creative
commons licenses for free to the public. These licenses allow
creators to communicate which rights they reserve, and which
rights they waive for the benefit of recipients or other creators.
Wikipedia is one of the notable web-based projects using one of
its licenses.
BSD LICENSE
The BSD license is a class of extremely simple and very liberal
licenses for computer software that was originally developed at
the University of California at Berkeley (UCB). It was first used
in 1980 for the Berkeley Source Distribution (BSD), also known
as BSD UNIX, an enhanced version of the original UNIX
operating system that was first written in 1969 by Ken
Thompson at Bell Labs.
The only restrictions placed on users of software released
under a typical BSD license are that if they redistribute such
software in any form, with or without modification, they must
include in the redistribution (1) the original copyright notice, (2)
a list of two simple restrictions and (3) a disclaimer of liability.
These restrictions can be summarized as (1) one should not
claim that they wrote the software if they did not write it and (2)
one should not sue the developer if the software does not
function as expected or as desired. Some BSD licenses
additionally include a clause that restricts the use of the name
of the project.
The permissive nature of the BSD license allows companies to
distribute derived products as proprietary software without
exposing source code and sometimes intellectual property to
competitors. Searching for strings containing "University of
California, Berkeley" in the documentation of products, in the
static data sections of binaries and ROMs, or as part of other
information about a software program, will often show BSD
code has been used. This permissiveness also makes BSD
code suitable for use in open source products, and the license
is compatible with many other open source licenses.
BSD operating systems can run much native software of
several other operating systems on the same architecture,
using a binary compatibility layer. Much simpler and faster than
emulation, this allows, for instance, applications intended for
Linux to be run at effectively full speed. This makes BSDs not
only suitable for server environments, but also for workstation
ones, given the increasing availability of commercial or closed-
source software for Linux only. This also allows administrators
to migrate legacy commercial applications, which may have only
supported commercial Unix variants, to a more modern
operating system, retaining the functionality of such applications
until they can be replaced by a better alternative.
GNU GENERAL PUBLIC LICENSE
The GNU General Public License (GNU GPL or simply GPL) is
a widely used free software license, originally written by Richard
Stallman for the GNU project.
The GPL is an example of a powerful copyleft license that
requires derived works to be available under the same copyleft.
Under this philosophy, the GPL grants the recipients of a
computer program the rights of the free software definition and
uses copyleft to ensure the freedoms are preserved, even when
the work is changed or added to. This is in distinction to
permissive free software licenses, of which the BSD licenses
are the standard examples.
The GPL was designed as a license, rather than a contract. In
some Common Law jurisdictions, the legal distinction between a
license and a contract is an important one: contracts are
enforceable by contract law, whereas licenses are enforced
under copyright law. However, this distinction is not useful in the
many jurisdictions where there are no differences between
contracts and licenses, such as Civil Law systems.
Those who do not agree to the GPL's terms and conditions do
not have permission, under copyright law, to copy or distribute
GPL licensed software or derivative works. However, if they do
not redistribute the general public licensed program, they may
still use the software within their organization however they like,
and products constructed by the use of the program are not
covered by this license
APACHE LICENSE
The Apache License is a free software license authored by the
Apache Software Foundation (ASF). The Apache License
requires preservation of the copyright notice and disclaimer, but
it is not a copyleft license — it allows use of the source code for
the development of proprietary software as well as free and
open source software.
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
All software produced by the ASF or any of its projects or
subjects is licensed according to the terms of the Apache
License. Some non-ASF software is licensed using the Apache
License as well. As of July 2009, over 5000 non-ASF projects
located at SourceForge.net are available under the terms of the
Apache License. In a blog post from May 2008 Google
mentioned that 25% of the 100,000 projects then hosted on
Google Code were using the Apache License.
PHP LICENSE
The PHP License is the software license under which the PHP
programming language is released. The PHP License is a non-
copyleft free software license according to the Free Software
Foundation and an open source license according to the the
Open Source Initiative. This license is GPL-incompatible due to
restrictions on the use of the word PHP.
MIT LICENSE
The MIT License is a free software license originating at the
Massachusetts Institute of Technology (MIT), used by the MIT X
Consortium. It is a permissive license, meaning that it permits
reuse within proprietary software on the condition that the
license is distributed with that software. The license is also
GPL-compatible, meaning that the GPL permits combination
and redistribution with software that uses the MIT License.
According to the Free Software Foundation, the MIT License is
more accurately called the X11 license, since MIT has used
many licenses for software and the license was first drafted for
the X Window System.
Software packages that use the MIT License include Expat,
PuTTY, the Mono development platform class libraries, Ruby on
Rails, Lua (from version 5.0 onwards), and the X Window
System, for which the license was written.
Some software packages dual license their products under the
MIT License, such as the JavaScript library jQuery, which is
licensed under both the MIT and GNU General Public License
licenses.
MOZILLA PUBLIC LICENSE
The Mozilla Public License (MPL) is a free and open source
software license. Version 1.0 was developed by Mitchell Baker
when she worked as a lawyer at Netscape Communications
Corporation and version 1.1 at the Mozilla Foundation. The
MPL is characterized as a hybridization of the modified BSD
license and GNU General Public License.
The MPL is the license for the Mozilla Application Suite, Mozilla
Firefox, Mozilla Thunderbird and other Mozilla software. The
MPL has been adapted by others as a license for their software,
most notably Sun Microsystems, as the Common Development
and Distribution License for OpenSolaris, the open source
version of the Solaris 10 operating system, and by Adobe, as
the license for its Flex product line.
The license is regarded as a weak copyleft. Specifically, source
code copied or changed under the MPL must stay under the
MPL. The MPL was approved both as an Open Source software
license by the Open Source Initiative and as a Free Software
license by the Free Software Foundation.
ECLIPSE PUBLIC LICENSE
The Eclipse Public License (EPL) is an open source software
license used by the Eclipse Foundation for its software. It
replaces the Common Public License (CPL) and removes
certain terms relating to patent litigation.
The Eclipse Public License is designed to be a business-
friendly free software license, and features weaker copyleft
provisions than contemporary licenses such as the GNU
General Public License (GPL). The receiver of EPL-licensed
programs can use, modify, copy and distribute the work and
modified versions, in some cases being obligated to release
their own changes.
The EPL is approved by the Open Source Initiative (OSI) and
the Free Software Foundation (FSF).
BEYOND SOFTWARE
Most of these licenses deal with the freedoms relating to
software. However many of these licenses are not confined to
software. Licenses such as creative commons, for instance, are
used increasingly for intellectual property beyond software.
The best example of this is wikipedia, where the content of each
and every article is subject to the creative commons license. It
is not uncommon for one to find ebooks, blogs etc that are
subject to creative commons licensing.
An extension of this idea can apply to even print media. If you
have not by now noticed it, the bottom right of this page has the
creative commons license symbol. It means that each and
every article and content in this publication is subject to creative
commons licensing.
So do feel free to copy, modify, and redistribute :-)
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
The Man Behind The
Revolution : Richard
Stallman
Revathy Lal
Richard Matthew Stallman (born March
16, 1953), often abbreviated "rms", is an
American software freedom activist, and
computer programmer. In September
1983, he launched the GNU Project to
create a free Unix-like operating system,
and has been the project's lead architect
and organizer. With the launch of the GNU
Project, he initiated the free software movement and, in October
1985, set up the Free Software Foundation.
Stallman pioneered the concept of copyleft and is the main
author of several copyleft licenses including the GNU General
Public License, the most widely used free software license.
[Stallman has also developed a number of pieces of widely-
used software, including the original Emacs, the GNU Compiler
Collection, and the GNU Debugger. He co-founded the League
for Programming Freedom in 1989.
In June 1971, as a first year student at Harvard University,
Stallman was known for his strong performance in Math 55, and
became a programmer at the MIT Artificial Intelligence
Laboratory. There he became a regular in the "hacker"
community. While a graduate student at MIT, Stallman
published a paper on an AI truth maintenance system called
dependency-directed backtracking with Gerald Jay
Sussman.This paper was an early work on the problem of
intelligent backtracking in constraint satisfaction problems. As of
2003, the technique Stallman and Sussman introduced is still
the most general and powerful form of intelligent backtracking.
The technique of constraint recording, wherein partial results of
a search are recorded for later reuse, was also introduced in
this paper. When Brian Reid in 1979 placed "time bombs" in
Scribe to restrict unlicensed access to the software, Stallman
proclaimed it "a crime against humanity." He clarified, years
later, that it is blocking the user's freedom that he believes is a
"crime", not the issue of charging for the software.
In 1980, Stallman and some other hackers at the AI Lab were
refused access to the source code for the software of the first
laser printer, the Xerox 9700. Stallman had modified the
software on an older printer (the XGP, Xerographic Printer), so
it electronically messaged a user when the person's job was
printed, and would message all logged-in users when a printer
was jammed. Not being able to add this feature to the Dover
printer was a major inconvenience, as the printer was on a
different floor from most of the users. This one experience
convinced Stallman of people's need to be free to modify the
software they use. Stallman argues that software users should
have the freedom to "share with their neighbor" and to be able
to study and make changes to the software that they use. He
maintains that attempts by proprietary software vendors to
prohibit these acts are "antisocial" and "unethical". The phrase
"software wants to be free" is often incorrectly attributed to him,
and Stallman argues that this is a misstatement of his
philosophy. He argues that freedom is vital for the sake of users
and society as a moral value, and not merely for pragmatic
reasons such as possibly developing technically superior
software.
In January 1984, Stallman quit his job at MIT to work full-time
on the GNU project, which he had announced in September
1983.
GNU's NOT LINUX!
It is a common misconception among many to think that Linux is
an OS and that GNU is some
company or organization that made
a lot of software in it (gcc, gnome,
etc). GNU is actually an operating
system that has not yet materialized
entirely. Software such as gcc,
emacs, etc credited to Stallman
personally and many others of the
Free Software Foundation and the GNU Project are the pieces
in the puzzle that is to form the OS that is GNU.
GNU is a long running process. Unfortunately, it had a missing
link, its kernel. Linux is the kernel that was used to fill the gap in
the picture. Thus, we today have GNU/Linux. Does this mean
that the GNU project is over? Not at all. Work is still going on
the kernel, named Hurd. Debian has even made a Debian
GNU/Hurd distribution, but being a work in progress it is still
unstable.
Why build another kernel when we have linux? Why not say that
GNU project is complete? The answer to these questions is not
that easy to give. There are philosophical differences amongst
those in the Free Software/Open Source community. One may
not believe it but Richard Stallman and Linus Torvalds have big
differences in opinion when it comes to a number of matters.
We may dig deeper into all these issues when we investigate
the history of Free Software (maybe in another issue).
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
GNU PROJECT AND FREE SOFTWARE
ACTIVISM
In 1985, Stallman published the GNU
Manifesto, which outlined his motivation for
creating a free operating system called GNU,
which would be compatible with Unix.Soon
after, he started a non-profit corporation
called the Free Software Foundation to employ free software
programmers and provide a legal infrastructure for the free
software movementStallman popularized the concept of
copyleft, a legal mechanism to protect the modification and
redistribution rights for free software. It was first implemented in
the GNU Emacs General Public License, and in 1989 the first
program-independent GNU General Public License (GPL) was
released. By then, much of the GNU system had been
completed. Stallman was responsible for contributing many
necessary tools, including a text editor (Emacs), compiler
(GCC), debugger (gdb), and a build automator (gmake). The
notable exception was a kernel. In 1990, members of the GNU
project began a kernel called GNU Hurd.In 1991, Linus
Torvalds, a Finnish student, used the GNU development tools to
produce the Linux kernel. The existing programs from the GNU
project were readily ported to run on the resultant platform;
most sources use the name Linux to refer to the general-
purpose operating system thus formed.
In August 2006 at his meetings with the government of Kerala,
he persuaded officials to discard proprietary software, such as
Microsoft's, at state-run schools. This has resulted in a
landmark decision to switch all school computers in 12,500 high
schools from Windows to a free software operating system.
After personal meetings, Stallman has obtained positive
statements about the free software movement from the then-
President of India, Dr. A.P.J. Abdul Kalam, French 2007
presidential candidate Ségolène Royal, and the president of
Ecuador Rafael Correa.Stallman's staunch advocacy for free
software inspired "Virtual Richard M. Stallman" (vrms), software
that analyzes the packages currently installed on a Debian
GNU/Linux system, and report those that are from the non-free
tree.
Stallman has devoted the bulk of his life’s energies to political
and software activism. Professing to care little for material
wealth, he explains that “I've always lived cheaply … like a
student, basically. And I like that, because it means that money
is not telling me what to do. “
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Linux vs Windows – For The
Common User
Maxwell Felix
One of the biggest difficulties in migrating from Windows to
Linux is the lack of knowledge about comparable software.
Newbies usually search for Linux analogs of Windows software,
and advanced Linux-users cannot answer their questions since
they often don't know too much about Windows :). Here's a list
of Linux equivalents / replacements / analogs of Windows
software.
Description of
the program,
executed task
Windows Linux
Web browser Internet Explorer, Opera,
Firefox, ...
Firefox, Galeon,
Konqueror, Opera,
Nautilus
Email client Outlook Express,
Thunderbird, ...
Evolution,
Thunderbird,
Kmail, ..
Instant
Messaging
clients
ICQ Lite, ICQ Corp,
MSN,Yahoo, ...
Licq, GnomeICQ,
Pidgin, ..
Work with
compressed
files
WinZip, WinRar, 7-Zip, .. Ark (kdeutils), 7-Zip,
..
Text editor Notepad, WordPad,
TextPad, Vim,
Xemacs, ...
Kedit, Gedit, Vim,
Kate(KDE),
Kedit(KDE), ...
Viewing PDF Adobe Reader,
GhostView, ...
Adobe Reader,
Xpdf, GhostView, ...
Text to speech MS text to speech KDE Voice Pluggin,
Festival,
Emacspeak,
VoiceText, ...
Music / mp3 /
ogg players
Windows Media Player,
Winamp, ...
Mplayer, Xine,
Amarok, ...
Programs for
CD/DVD
burning with
GUI
Nero, Roxio Easy CD
Creator, ...
K3b, Nero, Gnome
Toaster, ...
Graphic Editor Photoshop, Gimp Gimp,
ImageMagick, ..
Office Suite Ms Office, OpenOffice,... OpenOffice,
StarOffice, Koffice,
Tex, LaTeX
Games Civilization: Call To
Power, Quake 1,2,3,
Counterstrike,
Civilization: Call To
Power, Quake
1,2,3, Counterstrike,
WYSIWYG
html editor
Dreamweaver, Ms
Frontpage, Mozilla
Composer, OpenOffice
HTML editor
Mozilla Composer,
Openoffice HTML
editor, Amaya, IBM
WebSphere
Homepage Builder,
JXHTMLEDIT(Java)
Web-server Apache, IIS, Roxen, wn,
cern-httpd, dhttpd,
caudium, aolserver, Boa
Apache, Xitami,
Thttp, Boa,
Caudium, Roxen,
Zeus, Thy
Database
engine
MySQL, IBM DB2, MS
SQL, Oracle, ...
PostgreSQL,
MySQL, IBM DB2,
Oracle, ...
Math system
in Matlab style
Matlab Matlab[FTP],
Octave, ....
CAD/CAM/CAE AutoCAD, Microstation,
ArchiCAD
Varcon, Linuxcad,
Varicad, Cycas, ...
Emulation of
the circuit
Electronic Workbench,
Altera MaxPlus+
Geda, Oregano,
Xcircuit, ...
IDE Microsoft VisualStudio
.net, Eclipse, Boa
Constructor, PythonCard
CodeForge,
Kdevelop+Qt3
Designer, Eclipse,
Emacs/Xemacs, ...
Finally, let me add that most Windows software can run very
well in Linux with a little help from the emulator Wine. So if you
can't stop using Photoshop and switch to Gimp, Wine is the way
to go. If you are hooked on that Windows game, Wine can help
you. However remember, you are not truly free when you rely
on an emulator. :)
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Installing Linux
Vineeth Kartha
The journey of a thousand miles begins with a single step. So
let us start our journey into the world of FOSS with the
installation of any one distro of Linux (UBUNTU 9.10).
The installation of ubuntu 9.10 is amazingly simple and fast
compared to Windows Vista or even windows 7.
But still we'll go through a brief step by step process for
newbies...
1)Insert the cd and restart the system
You will see the wallpaper for a few seconds. When
the installer appears, you will be able to select your native
language for the entire installation process. Click the "Forward"
button to continue...
Where are you?
The second screen will feature a map of the Earth. Upon the
selection of your current location, the time for the final system
will adjust accordingly. You can also select your current location
from the drop down list situated at the bottom of the window.
Click the "Forward" button after you have selected your desired
location...
Test your keyboard
On the third screen, you will be able to choose a desired
keyboard layout. But the default automatic selection should
work for most of you. Click the "Forward" button when you have
finished with the keyboard configuration...
Hard disk partitioning
You have four options here:
1. If you have another operating system (e.g. Windows XP) and
you want a dual boot system, select the first option: "Install
them side by side, choosing between them at each startup."
This option will ONLY appear if you have another operating
system installed, such as Microsoft Windows. Remember that,
after the installation, the Windows boot loader will be
overwritten by the Ubuntu boot loader!
2. If you want to delete your existing operating system, or the
hard drive is already empty and you want to let the installer
automatically partition the hard drive for you, select the second
option, "Use the entire disk."
This option is recommended for most users who do not have
another operating system installed or who want to erase an
existing one, for example Windows OS.
3. The third choice is "Use the largest continuous free space"
and it will install Ubuntu 9.10 in the unpartitioned space on the
selected hard drive.
4. The fourth choice is "Specify partitions manually" and it is
recommended ONLY for advanced users, to create special
partitions or format the hard drive with other filesystems than
the default one. But it can also be used to create a /home
partition, which is very useful in case of reinstalling the whole
system.
Here's how you do a manual partitioning with
/home:
- Select the "Specify partitions manually (advanced) and click
the "Forward" button;
- Make sure that the selected hard drive is the right one.
/dev/sda is the first physical hard drive. /dev/sdb is the second
hard drive in your machine. So, make sure that you know which
is the one you want to format! Otherwise, you will lose ALL
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
YOUR DATA on that hard drive;
- Let's say that the selected drive is empty (no other operating
system or important data on it), but it has some partitions on it.
Select each one of those partitions and click the "Delete"
button. After a few seconds, it will say "free space". Do this with
the other partitions from the selected hard drive, until they're all
deleted and you have a single "free space" line;
- With the "free space" line selected, click on the "Add" button.
In the new window, type 2000 in the "New partition size in
megabytes" field and select the "swap area" option from the
"Use as:" drop down list. Click the OK button and, in a few
seconds, you'll notice a "swap" line with the specified size;
- With the "free space" line selected, click on the "Add" button.
In the new window, select the "Primary" option, type a value
between 10,000 and 50,000 in the "New partition size in
megabytes" field and select / as the "Mount point". Click the OK
button and in a few seconds, you'll notice an "ext4 /" line with
the specified size;
- With the "free space" line selected, click on the "Add" button.
In the new window, select the "Primary" option, type a value
between 30,000 and 50,000 (or whatever space you have left
on the drive) in the "New partition size in megabytes" field and
select /home as the "Mount point." Click the OK button and, in a
few seconds, you'll notice an "ext4 /home" line with the
specified size.
This is how your partition table should look like. If so, click the
"Forward" button to continue with the installation...
WARNING: Be aware that all the data on the
selected hard drive or partition will be ERASED
and IRRECOVERABLE.
Click the "Forward" button to continue with the installation...
Who are you?
On this screen, you must do exactly what the title says. Fill in
the fields with your real name, the name you want to use to log
in on your Ubuntu OS (also known as the "username," which
will be required to log in to the system), the password and the
name of the computer (automatically generated, but can be
overwritten).
Also at this step, there's an option called "Log in automatically."
If you check the box on this option, you will automatically be
logged in to the Ubuntu desktop. Click the "Forward" button to
continue...
Are you really ready for Ubuntu?
Click the "Install" button to start the installation process...
The Ubuntu 9.10 (Karmic Koala) operating system will be
installed...
After approximately 10 to 18 minutes (depending on your
computer's specs), a pop-up window will appear, notifying you
that the installation is complete, and you'll need to restart the
computer in order to use the newly installed Ubuntu operating
system. Click the "Restart Now" button...
The CD will be ejected; remove it and press the "Enter" key to
reboot. The computer will be restarted and, in a few seconds,
you will see the Ubuntu boot splash and Xsplash...
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Linux Hacking
Vineeth Kartha
Aparna
What makes Linux so special compared to windows? Its the
ability to modify the whole system and make it function
according to our wish. In this column we aim to introduce to you
some basic commands and details that you should know about
Linux. Linux is an operating system that coordinates the
working of the hardware and software and its free of licensing
and such other hurdles a hacker has to face.
GNU/Linux is not that different from other operating systems on
the surface. You point and click using the mouse and call down
menus to get programs to work. However, these icons and
windows are just the sweet candy coating on top of a much
older system, a system of programs designed to be accessed
by the command line.
If you know the correct commands, then you can start any
program, check your computer’s status, and see what files you
have stored without having to find the listing in your menu. The
command line is an interface that allows you to talk directly to
your computer using words called commands
FILES AND FILE SYSTEMS
In Linux everything is treated as a file, the documents that we
save on the system, the directories in which the folders are
present and even the I/O devices are treated as files. Almost
everything you do on a computer involves one or more files
stored locally or on a network. These files are organized in a
hierarchical structure we call the file system. Linux uses the ext
file systems by default (e.g. ext3 or ext4). In this discussion we
would like to use the terns folder and directory to mean the
same.
Your file system's lowest folder / (read as 'root') contains the
following subfolders:
/binEssential user command binaries (for use by all
users)
/bootStatic files of the boot loader, only used at system
startup
/devDevice files, links to your hardware devices like
/dev/sound, /dev/input/js0 (joystick)
/etc Host-specific system configuration
/homeUser home directories. This is where you save your
personal files
/lib Essential shared libraries and kernel modules
/mntMount point for a temporarily mounted filesystem like
/mnt/cdrom
/opt Add-on application software packages
/usr
/usr is the second major section of the filesystem.
/usr is shareable, read-only data. That means that
/usr should be shareable between various FHS-
compliant hosts and must not be written to. Any
information that is host-specific or varies with time is
stored elsewhere.
/var
/var contains variable data files. This includes spool
directories and files, administrative and logging data,
and transient and temporary files.
/procSystem information stored in memory mirrored as
files.
The only folder a normal user needs to use is /home/you/ this is
where you will be keeping all your documents.
e.g.
/home/gecb/Documents
/home/gecb/Music
/home/gecb/Music/malayalam
File names are case sensitive, "myfile" and "MyFile" are totally
different files.
Who and what is root
Linux has one special user called root (this is the user name).
Root is the "system administrator" and has access to all files
and folders. This special user has the right to do anything.
Important jobs like installation of software, the maintenance of
the system, etc are root's job. Practically speaking a non root
user can do no big harm even when they mess up and what
ever harm was done will be done to them and them alone. You
should never log in as root unless you actually need to do
something that requires it!
Use su command to temporary become root and do the things
you need, again: never log into your system as root!
Though there is only one root, we can get privileges if
authorized. The sudo command is used to execute a command
with root privileges, without actually logging in as root.
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Root is only for system maintenance, this is not a regular user
and using root for everything is a very bad idea!.
You can execute a command as root with:
su -c 'command done as root'
or sudo 'command'.
In OS' like fedora we specify the password for root when we
install it. But in Ubuntu the root password is set by the computer
itself.
Its better to leave it that way but still you can change the root
password by typing
sudo passwd
it will ask for a new UNIX password but its always good to keep
the root user untouched and use the sudo command instead.
There is a group of users (administrators) that are allowed to
use the sudo command only they can use it. Well get into
details of this in another issue.
Opening a command shell / terminal
To learn Linux, you need to learn the shell command line in a
terminal emulator.
In KDE:K → System → Konsoll to get a command shell)
in Gnome:Applications → accessories→ terminal
Pressing CTRL-ALT-F1 to CTRL-ALT-F6 gives you the console
command shell windows, while CTRL-ALT-F7 gives you the
graphical interface.
xterm is the standard XFree console installed on all boxes, run
it with xterm (press ALT F2 in KDE and Gnome to run
commands).
So what is a shell its like a software helps the user to
communicate with the kernel which is actually the soul of the
computer.
The default shell is bash (Bourne Again SHell- named after its
inventor Stephen Bourne) then there are Korn shell, Csh (c
shell) etc. An indepth discussion on all these is left to be
handled in a later column.
The default shell can be changed by typing chsh and then enter
the required shell (ksh or csh)
Your first Linux commands
Now you should have managed to open a terminal shell and are
ready to try your first Linux commands. Simply ask the
computer to do the tasks you want it to using it's language and
press the enter key (the big one with an arrow :-) ). You can add
a '&' after the command to make it run in the background (your
terminal will be available while the job is done). It can be
practical to do things like moving big divx movies or
compressing a large file as a background process.
Commands are written in a particular way. The command is
typed first with no spaces in the name. Then after a space, you
can sometimes modify the command by adding what are called
options. Options change or limit the way the command is
executed. Options are usually preceded by a dash. A command
may also include the name of a file or directory that you want
the command to work on. The finished command will look
something like this.
$command -option file
To get help about any command type
$man 'command name'
ls – list contents of directory
ls lists the files in the current working folder. This is the first
command to try out.
The command may be used in a number of ways:
$ls
$ls -a (displays all files including hidden ones)
$ls -l (long format, displays file type, permissions, owner, etc)
$ls -F (appends * to names of executable. / for directory)
$ls -R (recursively list all subdirectories)
$ls f.png (list file with name f.png if it is in current directory)
As seen in the last example ls allows us to list specific files.
That is,$ls filename lists the file if present in current directory.
This may seem like a useless feature but when combined with
the native support for regular expressions that linux offers we
can do amazing things. For e.g.,
$ls *.png (lists all files with names ending in '.png')
Linux regular expressions are, in simple terms, patterns which
may be matched by a set of file names. This is a topic too big to
be covered in this article. For the moment lets just understand
that as the previous example shows, a * in a file name for a
command represents any string. That is *.png represents the
set a.png, ab2.png, pq.png, etc of files in the current directory.
You may by now guessed that this makes it impossible to have
* in file names. There are many such characters that are not to
be used in file names.
Do note that all files that accept file names as input accept
regular expressions (nothing special to ls).
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
pwd - print name of current/working directory
pwd prints the fully resolved name of the current (working)
director.
cd - change directory
cd stands for change (working) directory and that's what it does.
The folder below you (unless you are in /, where there is no
lower directory) is called "..".
To go one folder down:
$cd..
To change to home folder type:
$cd ~
Change into a folder somewhere else:
$cd /pub/video
The / in front of pub means that the folder pub is located in the /
(lowest folder).
Note that as '..' represents the parent directory '.' represents the
current directory.
chmod – change permissions of a file
The permissions are:
r-read
w-write
x-executable
d- directory
on executing the command ls -l we can see the file names with
the permissions, and they appear as:
-rw-r--r-- 1 gecb gecb 182 2009-12-24 20:02 graph.c
drwxr-xr-x 6 gecb gecb 4096 2009-12-24 20:01 libgraph-1.0.1
here the first part shows the permissions the first character
shows if its a directory or not. Then the next 3 character shows
permission for the owner then comes the permission for the
group and finally comes for the rest of the users.
e.g.,
rwxrwxrwx : the file can be read written and executed b all
rwx --- --- :file can be accessed only by the owner
To make a file executable by any user:
$chmod a+x myfile
Similarly we can use the other permissions too. The permission
can also be entered as octal numbers. rwx -- x--x can be written
as 111001001 in binary and its equivalent octal is 711. So the
command can be issued as chmod 711 myfile
mkdir - makes directory
Folders are created with the command :
$mkdir foldername
To make a long path, use mkdir -p :
$mkdir -p /use/one/command/to/make/a/long/path/
You can make multiple folders in bash and other shells with
{folder1,folder2} :
$mkdir /usr/local/src/bash/{old,new,dist,bugs}
rmdir – remove directory
The command rmdir deletes folders. Usage is of same form as
mkdir. However note that we can only remove empty
directories.
passwd - changes your login password
To change your password in Linux, type:
$passwd
The root user can change the password of any user by running
passwd with the user name as argument:
$passwd gecb
will change gecb's password. Running passwd without
arguments as root changes the root password.
rm - remove
Files are deleted with the command rm:
$rm /home/you/youfile.txt
To delete folders, use rm together with -f (Do not prompt for
confirmation) and -r(Recursively remove directory trees) and
folders must be empty:
$rm -rf /home/you/foo/
cp- copy
Its used to copy a file from source to destination.
$cp source destination
mv- move
Although called move, this command has the added use of
renaming files. It is used as,
$mv source_file destination_file
$mv oldname newname
cat - concatenate
Used to concatenate (combine) two or more files.
$cat file1 file2 > file3
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Often it is also used to display the contents of a file.
$cat file
more
Used to diplay a file page by page
$more file
less
Similar to more but allows backward movement in file as well as
forward movement.
cal – calendar
To see calendar for current month,
$cal
Other forms of use,
$cal yyyy
$cal mm
$cal mm yyyy
who
To know who all are logged in. An interesting use of it is,
$who am i
which lists your user's details.
shutdown
Used to shutdown the system it should be executed as the root
or using the sudo command. It has several options like
-r for reboot
-P to switch off
-c to cancel the issued shutdown command
the shutdown command can also be issued with time as an
argument so that it shuts down at the specified time.
$sudo shutdown -P +m
where m is the number of minutes to shutdown. To shutdown
instantly use now instead of +m
ln – link
This is used to create symbolic links. A symbolic link is a "file"
pointing to another file. To make a symbolic link,
$ln /original/file /new/link
This makes /original/file and /new/link the same file - edit one
and the other will change. The file will not be gone until both
/original/file and /new/link are deleted.
You can only do this with files. For folders, you must make a
"soft" link. To make a soft symbolic link,
$ln -s /original/file /new/link
E.g.,
$ ln -s /usr/src/linux2 /usr/src/linux
Note that -s makes an "empty" file pointing to the original
file/folder. So if you delete the folder a symlink (symbolic link)
points to, you will be stuck with a dead symlink (just rm it).
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
Comic Corner
LINUX USER AT BEST BUY
WINDOWS 7
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
10 Years Of Linux
Pranoy P
The Linux technology, development model, and community
have all been game-changing influences on the IT industry, and
all we can really do is stand back and look at it all. Much too
much has happened with Linux in the last 10 years to do
anything like a complete job of listing the important events and
technological advances surrounding this operating system.
1. Linux Professional Institute certification
In 2000, LPI announced the availability of test 1a, the first exam
in its new Linux administrator certification program, a program
that now consists of seven tests across three certification levels.
2. Linux Kernel 2.4
The Linux 2.2 kernel was great — for standalone servers and
brave desktop users. It was only after the Linux 2.4 kernel was
introduced in January 2001 that Linux took dead aim at moving
from Web servers and branch file and print servers to running
the enterprise. Yes, it added some desktop-friendly features,
better device support in general and USB support that really
worked, but its improved support for clustering, multiple
processors and up to 64GBs of memory is what paved its way
to being an enterprise server powerhouse.
3. Samba
Andrew Tridgell's Samba with its
implementation of Microsoft's
Server Message Block (SMB)
protocol is such an important component of mixed networks
everywhere that we really didn't feel right not including it here.
4. Linux on S/390
"One box, one operating system" no longer applied to Linux
when it arrived on the S/390 mainframe in early 2000.
5. SE Linux
Released under the GPL by the US National Security Agency in
early 2001 and merged into the kernel since 2.6.0, Security
Enhanced Linux provides support for a number of access
control policy models, such as mandatory access control and
role-based access control.
6.Linux LiveCDs
A LiveCD lets you boot Linux on a machine
without actually installing anything on the hard
drive—Linux boots from the CD or DVD and
lives in RAM while running. Many distributions have LiveCD
versions, and there are a number of LiveCD distributions
created for specific tasks, such as system diagnosis and
recovery.
7. Linux clusters
Linux users early on started chaining multiple boxes together to
provide more fault tolerance or better performance. Beowulf, for
one, was an important early architecture for multi-machine
parallel computations. There's even a load-balancing cluster
LiveCD, ClusterKnoppix.
8. Linux supercomputing
Of course, tightly coupled, multi-core systems will always
outperform networked boxes. Blue Gene®/L and the now Blue
Gene/P running Linux are setting records in the most compute-
intensive technical and scientific workload environments.
9. Linux on Playstation
Sony has allowed and even
encouraged the installation of Linux
on its game consoles, and for
developers interested in exploring
Cell/B.E. programming, the PS3 is an
accessible option. Linux on the
Playstation makes a fine computer and all, but frankly, in the
greater scheme of things, we're not sure it changes the Linux
landscape all that much.
10. Virtualization
Virtualization allows one or more guest operating systems to run
on top of another operating system that acts as the host. The
2.6.20 kernel was the first to include the Kernel Virtual Machine
(KVM), but Xen, User-Mode Linux, QEMU, VMware, and other
virtualization technologies are important as well.
11. One Laptop Per Child
Announced in 2005, the OLPC project
was created to provide low-cost,
durable, connected computers to
underprivileged children around the
world. As much about the user interface
as the hardware, the Linux-based Sugar operating environment
is designed to encourage exploring and expressing rather than
focusing on traditional productivity tools.
12. Ubuntu
When South African millionaire Mark
Shuttleworth’s company, Canonical,
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
released the Debian-based Ubuntu in 2004, few could have
expected what a massive success it would become. Ubuntu
quickly became the most widely used Linux distribution by far,
especially on the desktop, and has brought Linux to the masses
like no other distribution.
13.Cellphones
Linux on cellphones is fast becoming popular and is being
adopted by major manufacturers line Nokia and HTC. We have
the revolutionary Nokia N900 running Maemo and the HTC
Hero running Google Android. Both are Linux for smartphones
and are highly customizable and developer friendly.
14. The Netbook arrives
Perhaps it wasn't too surprising that Dell was followed by Asus,
which introduced a new kind of laptop: the Linux-powered
netbook. Netbooks quickly became wildly popular, which caught
everyone by a surprise — no one more so than Microsoft, which
was forced to bring XP Home out of retirement to compete with
Linux.
Today, despite Microsoft's claims that Windows has beaten
Linux out of the low-end netbook space, Linux is holding its own
on the global market. Indeed, the entire netbook and desktop
Linux market may be in for a complete revolution thanks to the
arrival of the most recent desktop Linux player: Google.
15.Oracle buys Sun
The decade ends with the sun
setting on one of the most
influential Unix and open source
companies to survive the 90s.
Custodian of Java, VirtualBox,
MySQL and OpenOffice.org, along with major contributions to
Gnome, Mozilla and the Linux kernel itself, the effects of Sun's
acquisition are yet to be realised. But whatever happens to Sun,
these projects are safeguarded, thanks to the open source
licences they use.
16. Google Chrome OS
Google, one of the only companies in the world
that's big enough to go head-to-head with
Microsoft, has thrown its hat into the desktop OS
ring with the announcement of the 2010 arrival of
the Chrome operating system. What I think makes this move
both especially interesting, and more likely to succeed, is that
Google isn't taking on Windows 7 on all desktops. No -- what
Google is doing is claiming that its Internet-based, Linux-
powered Chrome OS is all the 'desktop' people will need on
low-end systems like netbooks.
17. Cloud Computing
Cloud Computing has become the next buzzword for quite
some years, both bygone and the ones to come. From cloud
based storage to providing software as a service(SaaS), Cloud
Computing is really picking up on Desktop based computing.
Linux has a major role to play in Cloud Computing as we
already have a good number of Cloud based operating systems
and certain cloud based services supported in Linux. gOS,
Google Chrome OS and Ubuntu One are a few popular ones.
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
A Quick Look at C
Maxwell Felix
C is a very simple programming language. Something very hard to digest when we consider its power. In fact we call a family of laguages “C-like” due to their shared syntax and history. This includes those like C++, Java, Perl, PHP, etc. A thorough understanding of C is surely going to aid in learning any of these languages. So lets get started.What you need to start?First and foremost, what is needed is a c compiler. The compiler of choice is gcc from GNU. Its in all linux distributions. For the windows user a good choice would be Dev C++ ( don't worry about the name, C works in it ).The First ProgramIn the spirit of an ancient tradition, all first programs in a new language do just one simple thing. When executed, the display the words “Hello World!” on the screen.#include<stdio.h>int main(){
printf(“Hello World!”);return 0;
}Lets now examine what exactly we see in the above program of ours. The first line starting with the hash (#) is meant to include header files into our program.A header file in general holds part of our program that we have separated into a number of files. The above program is a very small one but in real life programs tend to be thousands of lines long and separating it into a number of files allows it to be easier to handle and understand.The header file included in our program is called 'stdio.h'. It holds the programs that we use for standard input/output (hence the name). An obvious question would be, “Who made this header file?” This header file is part of group of a number of other header files that are together called the C Standard Library. This essentially is a set of programs that have already been provided with the compiler for our use. They surely make a programmer's life a lot easier.Following the #include we find the int main() followed by flower brackets ({}) inside which we have some program code. This is called the main function. For the moment understand that all C programs will have the main(){ }. In C, the { and } symbols mark the beginning and end of a block of code. In this case, the block of code making up the main function contains two lines.The printf statement allows us to send output to standard output (display terminal).The return 0 returns an error code of 0 to the shell (which started the execution) that there was no errors.Lets get formalThe variablesA C variable may be thought of as a container that is used to hold a value. C requires us to declares all the variables that we use. A declaration tells C the name and type of the variable. For eg int i; declares a variable with name i and type int (integer).C supports a number of other standard types for variables such as char (for charcters), float (for real numbers), etc. All types of variables are declared int the same way,<type> <name>;e.g.int i;float ff;char o;There are a conditions that C imposes on variable declaration. 1. All variable declarations should be at the begining of a block ( {} ).
2. The names of variables should not be a number or special character (*,&,+,-, etc).3. Variable names are case sensitive. i.e apple is not aPpleNow lets see how all that we've seen so far is implemented in an actual program.#include <stdio.h> int main() { int a, b, c; a = 5; b = 7; c = a + b; printf("%d + %d = %d\n", a, b, c); return 0; }Here we have 3 integer variables a, b and c. Note that, we can declare more than one variable of a type by separating the names with a comma (,).We have stored (assigned) the value 5 to a, 7 to b, and the sum of a and b to c.The printf statement then prints the line "5 + 7 = 12." The %d placeholders in the printf statement act as placeholders for values. There are three %d placeholders, and at the end of the printf line there are the three variable names: a, b and c. C matches up the first %d with a and substitutes 5 there. It matches the second %d with b and substitutes 7. It matches the third %d with c and substitutes 12. Then it prints the completed line to the screen: 5 + 7 = 12. The +, the = and the spacing are a part of the format line and get embedded automatically between the %d operators as specified by the programmer.We use %d if the corresponding variable is integer, %c if character, %s for strings, and so on.User InputLets now accept the numbers from the user and display the sum.#include <stdio.h> int main() { int a, b, c; printf("Enter the first value:"); scanf("%d", &a); printf("Enter the second value:"); scanf("%d", &b); c = a + b; printf("%d + %d = %d\n", a, b, c); return 0; }Note that we have used a new statement called scanf. It looks a lot like printf in syntax but it accepts the input from the user into the specified variables. Also note that the variable names are given after an &.Branching and Looping In C, both if statements and while loops rely on the idea of Boolean expressions. Here is a simple C program demonstrating an if statement: #include <stdio.h> int main() { int b; printf("Enter a value:"); scanf("%d", &b); if (b < 0) printf("The value is negative\n"); return 0; }This program accepts a number from the user and tests it using an if statement to see if it is less than 0. If it is, the program prints a message.Here's slightly more complex example: #include <stdio.h> int main()
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
{ int b; printf("Enter a value:"); scanf("%d", &b); if (b < 0) printf("The value is negative\n"); else if (b == 0) printf("The value is zero\n"); else printf("The value is positive\n"); return 0; } In this example, the else if and else sections evaluate for zero and positive values as well. Here is a more complicated Boolean expression: if ((x==y) && (j>k)) z=1; else q=10; This statement says, "If the value in variable x equals the value in variable y, and if the value in variable j is greater than the value in variable k, then set the variable z to 1, otherwise set the variable q to 10." You will use if statements like this throughout your C programs to make decisions. In general, most of the decisions you make will be simple ones like the first example; but on occasion, things get more complicated. Notice that C uses == to test for equality, while it uses = to assign a value to a variable. The && in C represents a Boolean AND operation. Here are all of the Boolean operators in C: equality == less than < Greater than > Less than or equal <= Greater than or eual >= inequality != and && or || not ! You'll find that while statements are just as easy to use as if statements. For example: while (a < b) { printf("%d\n", a); a = a + 1; } This causes the two lines within the braces to be executed repeatedly until a is greater than or equal to b. This kind of repeated execution is called looping.C also provides a do-while structure: do { printf("%d\n", a); a = a + 1; } while (a < b); The differece between while and do-while is that the latter causes the block of code to be executed even when the condithion of while is false.The for loop in C is simply a shorthand way of expressing a while statement. For example, suppose you have the following code in C: x=1; while (x<10) { blah blah blah x++; /* x++ is the same as saying x=x+1 */ } You can convert this into a for loop as follows: for(x=1; x<10; x++) { blah blah blah
} Boolean expressions evaluate to integers in C, and integers can be used inside of Boolean expressions. The integer value 0 in C is False, while any other integer value is True. The following is legal in C: #include <stdio.h> int main() { int a; printf("Enter a number:"); scanf("%d", &a); if (a) { printf("The value is True\n"); } return 0; } If a is anything other than 0, the printf statement gets executed.ArraysAn array lets you declare and work with a collection of values of the same type. For example, you might want to create a collection of five integers. One way to do it would be to declare five integers directly: int a, b, c, d, e; This is okay, but what if you needed a thousand integers? An easier way is to declare an array of five integers: int a[5]; The five separate integers inside this array are accessed by an index. All arrays start at index zero and go to n-1 in C. Thus, int a[5]; contains five elements. For example: int a[5]; a[0] = 12; a[1] = 9; a[2] = 14; a[3] = 5; a[4] = 1;One of the nice things about array indexing is that you can use a loop to manipulate the index.#include <stdio.h> #define MAX 10 int a[MAX]; int main() { int i; for (i=0; i < MAX; i++) { a[i]=i; printf("%d\n",a[i]); } return 0; }This program has a lot of new stuff. Lets begin with the #define, it is used to define a macro. Here the macro MAX stands for the constant value 10. A macro is not a variable but just a simple way to represent a constant. So MAX=5 is wrong but i=MAX is correct if we have a variable i.Another new thing in this program is the declaration of array outside main(){}. This is perfectly ok. This type of variables are called global variables. We will deal with them later when we discuss functions.Structures Structures in C allow you to group variable into a package. Here's an example: struct rec { int a,b,c; float d,e,f; }; struct rec r; As shown here, whenever you want to declare structures of the type rec, you have to say struct rec. This line is very easy to forget, and you get many compiler errors because you absent-
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)
Fiat Lux! 02/2010
mindedly leave out the struct. You can compress the code into the form: struct rec { int a,b,c; float d,e,f; } r; where the type declaration for rec and the variable r are declared in the same statement. Or you can create a typedef statement for the structure name. For example, if you do not like saying struct rec r every time you want to declare a record, you can say: typedef struct rec rec_type; and then declare records of type rec_type by saying: rec_type r; You access fields of structure using a period(.), for example, r.a=5;.Do note that we can have arrays of structures as we have arrays of other types.FunctionsMost languages allow you to create functions of some sort. Functions let you chop up a long program into named sections so that the sections can be reused throughout the program. Functions accept parameters and return a result. C functions can accept an unlimited number of parameters. In general, C does not care in what order you put your functions in the program, so long as a the function name is known to the compiler before it is called. Function names should not begin with numbers or special characters just like variable names.#include<stdio.h>int fact(int i) { int j,k;
j=1; for (k=2; k<=i; k++) j=j*k; return j; }int main() { int i,b; scanf("%d", &b); i=fact(b); printf("%d\n",a[i]); return 0; }Here fact is a function accepting an integer argument (i) and returning another integer (j). It is now considered good form to use function prototypes for all functions in your program. A prototype declares the function name, its parameters, and its return type to the rest of the program prior to the function's actual declaration.#include <stdio.h>int add (int,int); /* function prototype for add */void main(){ printf("%d\n",add(3));}int add(int i, int j){ return i+j;}Note that functions can have any type of variable as parameter even arrays and structures.PointersTo understand pointers, it helps to compare them to normal variables. A "normal variable" is a location in memory that can hold a value. For example, when you declare a variable i as an integer, four bytes of memory are set aside for it. In your program, you refer to that location in memory by the name i. At the machine
level that location has a memory address. The four bytes at that address are known to you, the programmer, as i, and the four bytes can hold one integer value.
A pointer is different. A pointer is a variable that points to another variable. This means that a pointer holds the memory address of another variable. Put another way, the pointer does not hold a value in the traditional sense; instead, it holds the address of another variable. A pointer "points to" that other variable by holding a copy of its address. Because a pointer holds an address rather than a value, it has two parts. The pointer itself holds the address. That address points to a value. There is the pointer and the value pointed to. This fact can be a little
confusing until you get comfortable with it, but once you get comfortable it becomes extremely powerful. The following example code shows a typical pointer: #include <stdio.h> int main() { int i,j; int *p; /* a pointer to an integer */ p = &i; *p=5; j=i; printf("%d %d %d\n", i, j, *p); return 0; } The first declaration in this program declares two normal integer variables named i and j. The line int *p declares a pointer named p. This line asks the compiler to declare a variable p that is a pointer to an integer. The * indicates that a pointer is being declared rather than a normal variable. You can create a pointer to anything: a float, a structure, a char, and so on. Just use a * to indicate that you want a pointer rather than a normal variable. The line p = &i; will definitely be new to you. In C, & is called the address operator. The expression &i means, "The memory address of the variable i." Thus, the expression p = &i; means, "Assign to p the address of i." Once you execute this statement, p "points to" i. Before you do so, p contains a random, unknown address, and its use will likely cause a segmentation fault or similar program crash.Here is a cool aspect of C: Any number of pointers can point to the same address. For example, you could declare p, q, and r as integer pointers and set all of them to point to i, as shown here: int i; int *p, *q, *r;
p = &i; q = &i; r = p; Note that in this code, r points to the same thing that p points to, which is i. You can assign pointers to one another, and the address is copied from the right-hand side to the left-hand side during the assignment.Something to note in C is that pointers to structures use the operator -> to access members. There is also an interesting type of poiter called pointer to functions. What next?C is simple but its not all that simple to be distlled down to a three page article. However, this article has enough stuff in it to enable you to go the rest of the way on your own. So go ahead, find out about structure pointers, what a function pointer is, and so on.You have been shown the light. The rest is up to you :-)
This article is subject to creative commons licensing (http://creativecommons.org/licenses/by/3.0/)