/* * Program to get and echo a line of text. */ #include #include int main(void) { char line[80]; printf("enter a line of text\n"); /* unsafe way -- never do this! gets(line); */ fgets(line, sizeof line, stdin); /* if input fits into array, fgets stores '\n' character */ char *nl = strchr(line, '\n'); if (nl == NULL) { printf("line too long\n"); return 1; } else { *nl = '\0'; printf("line '%s'\n", line); return 0; } }