#include <stdio.h>
#include <stdlib.h>
#include <string.h>

 #define MAXLINE 1000 /*max line length */

int main(void) {
  char *s = malloc(MAXLINE);
  if (!s) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }  
  while(fgets(s, MAXLINE, stdin)) {
    char *newline = strchr(s, '\n');
    if (newline)
      *newline = '\0';
    printf("got: '%s'\n", s);
    if (!strcmp(s, "exit"))
      exit(EXIT_SUCCESS);
  }
  return feof(stdin) ? EXIT_SUCCESS : EXIT_FAILURE;
}