Your actual shell prompt may vary Shell prompt can be configured to whatever

Your actual shell prompt may vary shell prompt can be

This preview shows page 1 - 3 out of 3 pages.

In the above example, the symbol "%" denotes your shell prompt. Your actual shell prompt may vary. Shell prompt can be configured to whatever you like. The command cd sets your current directory to your home 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. Now go to the directory ~/lab02/hello using the command % 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
Image of page 1
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
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • One '14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture