/* * Program to get and echo two lines of input, discarding input that won't fit * in the array meant to hold the line read. (Yes, it's silly, but it's an * example of reading input in a "safe" way.) */ #include #include void get_and_echo(void) { char text[20]; printf("enter some text\n"); fgets(text, sizeof(text), stdin); printf("you entered: %s\n", text); if (text[strlen(text)-1] != '\n') { while (fgetc(stdin) != '\n'); } } int main(int argc, char *argv[]) { get_and_echo(); get_and_echo(); return 0; }