Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started