Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your programs must include the following information in comments: (1) problem nu

ID: 3808754 • Letter: Y

Question

Your programs must include the following information in comments: (1) problem number, (2) course information, (3) assignment, (4) date, and (5) student name. 1. (20 points) Modify the given read line function each of the following ways: a. Have it skip white space before beginning to store input characters. Name this function read line a b. Have it stop reading at the first white space character. Name this function read line b. c. Have it stop reading at the first new-line character, then store the new-line character in the string. Name this function read line c. d. Have it leave behind the characters that it doesn't have room to store. Do not read these from input. Name this function read line d. You will submit a program that calls each ofthe four read line functions. Your program should call each of the functions from main and display the resulting strings. Use these global constants for the whitespace characters: Global Constants const int horizontalTab 9; const int linefeed 10; const int verticalTab 11; const int space 32; Ifn int read line (char str0, int n) brief reads characters from standard input and stores them in str. *param[in] str character array "Vparam[in] n ength of str array * eturn number of characters stored in str

Explanation / Answer

Solution:

int read_line_a(char str[], int n) // Function definition

{

int ch, i=0; // Variables initialized

while((ch=getchar())!=' '){ // Read the input until newline occurs

if(i<n && ch!=" ") // If the sting str has a room to store and it is not a white space character. store it

str[i++]= ch; // Store the character

}

if(i<n) // after the loop is terminated and str is still empty, put null operator to show that the string is terminated

str[i]= ''; // null at the end of the input

return i;

}


b)

int read_line_b(char str[], int n) // Function definition

{

int ch, i=0; // Variables initialized

while((ch=getchar())!=' '){ // Read the input until newline occurs

if(i<n)

str[i++]= ch; // Store the character

if(ch==" ") // if a white space occurs the loop will be terminated

break;

}

if(i<n)

str[i]= '';

return i;

}

or we can do one more thing here

int read_line_b(char str[], int n)    // Function definition

{

int ch, i=0; // Variables initialized

scanf("%s", str); //simply using scanf does the same thing

return i;

}

c)

int read_line_c(char str[], int n)   // Function definition

{

int ch, i=0; // Variables initialized

while((ch=getchar())!=' '){// Read the input until newline occurs

if(i<n && ch!=" ")

str[i++]= ch; // Store the character

}

if(i<n)

str[i]= ' '; // After the loop is terminated new line character will be stored at the end of the string

return i;

}

d)

int read_line_a(char str[], int n)   // Function definition

{

int ch, i=0; // Variables initialized

while((ch=getchar())!=' '){// Read the input until newline occurs

if(i<n)

str[i++]= ch; // Store the character

}

if(i<n)

str[i]= '';

return i;

}

I hope this helps, hit the thumbs up if you like it.

Please go through the comments for better understanding.