--- In [email protected], Michael Comperchio <mcmp...@...> wrote:
>
> he did say he was accepting strings....
> can't accept a string without a second buffer :)

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

#define BUFSZ 1000

int main(void)
{
  char   buffer[BUFSZ], *s;
  size_t len;

  for (*(s = buffer) = '\0'; fgets(s, BUFSZ - (s - buffer), stdin); s += len) {
    /* Remove trailing \n added by fgets(). */
    if (((len = strlen(s)) > 0) && (s[len - 1] == '\n'))
    {
        s[--len] = '\0';
    }
  }

  printf("buffer=\"%s\"\n", buffer);

  return 0;
}

Run the program and enter:

one
two
three
<ctrl-D> or whatever to indicate EOF

buffer="onetwothree"

Reply via email to