Question
Exercise 1 : Complete the program below, which contains a function read_line that reads a line of text from the user. The function should read
Exercise 1: Complete the program below, which contains a function read_line that reads a line of text from the user. The function should read characters from the user using getchar() into a provided character array until one of the following conditions occurs.
The user enters a character (do not store the into the array)
The array is full (that is, size-1 characters have been entered)
Once either condition occurs, the function will add a null terminator to the end of the array and return the total number of characters read (not including the , if applicable).
#includeint read_line(char output_array[], int size){ /* Your code here */ } int main(){ char the_line[1000]; int num_read = 0; printf("Enter a line of input: "); num_read = read_line(the_line, 1000); printf("Characters read: %d ", num_read); printf("You entered: %s ", the_line); printf("Enter another line (of at most 4 characters): "); num_read = read_line(the_line, 5); printf("Characters read: %d ", num_read); printf("You entered: %s ", the_line); return 0; }
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