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

#define MAX 4

int main(int argc, char *argv[])
{
  FILE *f;
  char *s;
  char *v[MAX];
  char *p;
  int i, c;  
  char newline, comment, word;

  f = fopen(argv[1], "r");
  s = malloc(2000);
  p=s;
  c = getc(f);
  newline = comment = word = i = 0;
  while ( (c = getc(f)) != EOF )
    {
      if (c == '#')
	{
	  if (newline)
	    comment = 1;
	  continue;
	}
      if ( (newline = (c == '\n')) )
	{
	  if (comment)
	    comment = 0;
	  if (word)
	    {
	      word = 0;
	      *p++ = '\0';
	      if (i == MAX)
		break;
	    }
	  continue;
	}
      if (comment)
	continue;
      if (isspace(c))
	{
	  if (word)
	    {
	      word = 0;
	      *p++ = '\0';
	      if (i == MAX)
		break;
	    }
	  continue;
	}
      if (isalnum(c))
	{
	  if (! word)
	    {
	      v[i++] = p;
	      word = 1;
	    }
	  *p++ = c;
	}       
    }
  for (i = 0; i < MAX; i++)
    puts(v[i]);

  free(s);
  return 0;
}
