Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program #include #define LEN 10 char * getnchar(char * str, int n); int exer1(void) { char input[LEN]; char *check; getchar(); printf(Please enter 9 characters:

C Program #include #define LEN 10 char * getnchar(char * str, int n); int exer1(void) { char input[LEN]; char *check; getchar(); printf("Please enter 9 characters: "); check = getnchar(input, LEN - 1); if (check == NULL) puts("Input failed."); else puts(input); puts("Done. "); return 0; } char * getnchar(char * str, int n) { int i; int ch; for (i = 0; i < n; i++) { ch = getchar(); if (ch != EOF) str[i] = ch; else break; } if (ch == EOF) return NULL; else { str[i] = '\0'; return str; } } Answer these questions: 

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?

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago