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).

#include  int 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!