To see how to use the functions such as printf type the manual command man s 3

To see how to use the functions such as printf type

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

To see how to use the functions such as printf, type the manual command: man -s3 printfon 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 printfand exit3.Create a C source code getinput.cthat prompts the user to enter his full name. Save it in an appropriately named file such as getFullName.c. Compile it and execute it.Note the above program is a new program, so it should be placed inside a different directory, such as ~/lab02/getFullName. In future exercises, each new program should be placed in a separate directory.Some of you will realize that the program name a.outisn't always a good choice. If you wants to use a different name for your executable such as getFullName, use theoption -o of gcc, as in gcc getFullName.c -o getFullName. The option "-o"stands for "Output". Recompile your program to create an executable named getFullNameNote that, by convention, Unix commands or programs do not use extension names, unlike what is required under Windows (that is .exe and .com). So do not use extensionnames for your Unix executables.In the above program, we use the standard function fgetsto read a line of input froma file, which in this case is the standard input (stdin). Both fgetsand stdinare defined in the standard I/O library, so you must include <stdio.h>header file.stdin(standard input) is similar to System.inin Java, and cinin C++. stdout(standard output) is similar to System.outin Java, and coutin C++. stderr(standard error) is similar to System.errin Java, and cerrin C++.Note also in the above program, we read a line into a character array of size 128 characters. If you end the keyboard input with a ENTER key, fgetswill store the newline character in the character array. In some applications, you may need to strip this character away from the char array. For example the following code can be used tostrip the newline character away from the char array linen = strlen(line);if (line[n-1] == '\n') line[n-1] = '\0';In C, the last character in a string must always be the null character "\0". . . :
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture