Now use a text editor such as vi or pico but not GUI based text editors to

Now use a text editor such as vi or pico but not gui

This preview shows page 2 - 3 out of 5 pages.

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 file 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 the dot in this command, which indicates that the program a.out is under the current directory, 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 page for the standard C function exit too. 3. Create a C source code file getFullName.c that prompts the user (using fgets ) to enter his full name. Compile and execute it. Note: since the above program is a new program, you should place it inside a different directory, such as ~/lab02/getFullName . In future exercises, each new program should be placed in a separate directory.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 5 pages?

  • Winter '15
  • SyedAli
  • home directory, current directory, C standard library

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture