// This function demonstrates the use of the function // fgets() to read in a string of input (a whole line) // And how to stop reading in on Ctrl+D being pressed // fgets() uses the keyword NULL to indicate this // Sasha Vassar Week 5 Lecture 10 #include #define MAX_LENGTH 100 int main (void) { //1. Declare an array, where you will place the string char array[MAX_LENGTH]; printf("Type in a string to echo: "); //fgets(array, MAX_LENGTH, stdin); //printf("The echo of the typed word in string is: %s\n", array); //2. Read a string into the array until Ctrl+D is pressed, // which is indicated by NULL keyword while (fgets(array, MAX_LENGTH, stdin) != NULL) { printf ("The string is: \n"); printf("%s", array); //You can also use a function called fputs(array[], stream) //to do the same thing as line 15 - print out the string to terminal printf("Type in a string to echo: "); } return 0; }