Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: This question about Unix Exercises : The following exercise are designed to get familiar with Unix (Linux) systems. Question 2 Create a C source

Note:

This question about Unix Exercises :

The following exercise are designed to get familiar with Unix (Linux) systems.

image text in transcribed

Question 2 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. Compile it and execute it. Note the above program is part of C Exercise 2 in Lab 1, therefore, it should be placed inside directory lab01/c_ex2. Some of you may realize that the program name a.out isn't always a good choice. If you wants to use a different name for your executable such as getFullName, use the option -o of gee, as in gec getFullName.c -o getFullName. The option "-o" stands for "Output". Recompile your program to create an executable named getFullName. Note that, by convention, Unix commands or programs do not use extension names, unlike Windows (which uses .exe and.com). Therefore please do not use extension names for your Unix executables. In the above program, we use the standard I/O function fgets to read a line of input from a file, which in this case is the standard input (stdin). Both fgets and stdin are defined in the standard I/O library, therefore, you must include header file in your program. stdin (standard input) is similar to system.in in Java, and cin in CH. stdout (standard output) is similar to System.out in Java, and cout in CH.stderr (standard error) is similar to System.err in Java, and cerr in CH. 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, fgets will store the newline character in the character array. In some applications, you may need to strip this character off from the char array. For example the following code can be used to strip the newline character away from the char array line: n = strlen(line); if (line [n-1] == ' ') line [n-1] = '\0'; In C, the last character in a string must always be the null character "\0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago

Question

MH 0 8 ( ) ( ) ( ) ( ) - Al ( ) ( ) A B A B A B A B A B B

Answered: 1 week ago