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

Here is what you need to do: Put a comment to the side of each line explaining w

ID: 3707805 • Letter: H

Question

Here is what you need to do:

Put a comment to the side of each line explaining what that line of code accomplishes. Then answer the following questions (please number your answers and place your responses in the comments box when submitting your second program) ...

1. What is the maximum number of characters you can input?
2. What happens when you enter more than this number?
3. What is passed to the *getnchar() function?
4. What is returned from the *getnchar() function?
5. What happens when you press ctrl-d before any input? Why? (Which line of code effects this?)
6. What change would you need to make to allow the user to enter up to 50 characters into input[].
7. Aside from pressing ctrl-d at the beginning of a line, is there any way to enter less than 9 characters?

/*Programming Exercise 11-1 / #include #define LEN 10 char getnchar (char * str, int n); int exerl(void) char input [LEN] char *check; getchar ()i printf("Please enter 9 characters: "); check = getnchar (input, LEN - 1); if (checkNULL) puts ("Input failed."); else puts (input); puts ( "Done. " return 0; char getnchar (char * str, int n) int i; int ch; for (i = 0; i

Explanation / Answer

/* programming excercise 11-1 */

#include<stdio.h>

#define LEN 10 //max allowed size of an array

char *getchar(char *str, int n);

int excer1(void)

{

char input[LEN]; //declare array of size 10

char *check;

getchar();

printf("Please eneter 9 characters");

check = getnchar(input, LEN-1); //read 9 charactes in input array

if(check==NULL)

puts("Input Failed.");

else

puts(input); // print the array

puts(Done. ); // print done

return 0;

}

char *getnchar(char *str, int n) //for reading N characters

{

int i;

int ch;

for(int i = 0;i<n;i++) //iterate the loop until n

{

ch = getchar(); //read character by character

if(ch!=EOF)

str[i] = ch; //insert character in input array

else

break; //terminate if EOF character read

}

if(ch ==EOF)

return NULL; //return NULL if EOF character read

else{

str[i]=''; //add terminating character at the end

return str; //return string

}

}

Answers of the questions

1. we can put at max 9 characters

2. more than this number character numbers are getting ignored beacause

you passing LEN-1 in getnchar function

3. buffer that needs to fill and numner of characters we want to fill

4. it return staus about reading of input characters is successed or not

5. it will generate EOF character so loop will get terminated

6. need to increase LEN val upto 50(#define LEN 50)

7. by inserting termination character at the en