directory.
Now enter the directory
lab02
and then create a subdirectory named
hello
:
%
cd lab02
%
mkdir hello
Use the commands
cd
,
pwd
and
ls -l
to confirm that the above directory
hierarchy has been created.
4.
Now go to the directory
~/lab02/hello
using the command
5. %
cd ~/lab02/hello
In the above command, the symbol "~" stands for the home directory of the
current user. If your username is
john
, then
~john
stands for user john's home
directory.
Now use a text editor, such as
vi
or
pico
, but not GUI based text editors, to
create a C program
hello.c
that outputs
hello world
.
Name the file
hello.c
and save it in directory
hello
.
Compile your program with command
gcc hello.c
. This command
compiles the source code
hello.c
into an object code
hello.o
, and then links
the object code with the necessary library routines to form a complete,
executable, program named
a.out
.
Now list your current directory with command
ls -lt
. You will see your
original source code
hello.c
, possibly the object code
hello.o
and the
executable
a.out
.

Now run the program
a.out
by typing the command
./a.out
. Note in this
command, the dot indicates that the program
a.out
is under the current
directory, which is denoted by a single dot ".". You should see the
output
Hello world!
.
In C, we use functions such as
printf
,
putchar
, etc., to send output to the
standard output, which is similar to
System.out.print
in Java and
cout <<
in
C++. To use these functions, we must include the standard header
file
<stdio.h>
(standard I/O header file).
To see how to use the functions such as
printf
, type the manual
command:
man -s 3 printf
on the terminal. In this command, the option "-s
3" means section 3 of the manual. All standard C functions are grouped
under section 3.
Try to display the manual pages for the standard C
functions
printf
and
exit
.
6.
Create a C source code
getinput.c
that prompts the user to enter his full
name. Save it in an appropriately named file such as
getFullName.c
.


You've reached the end of your free preview.
Want to read all 5 pages?
- Fall '15
- DK
- directory, standard output, C standard library