/*
 * DICTEXPAND
 *
 * Summary:  Reads a dictionary (list of words, one per line) that has
 * been compressed by dictcompress and restores it to a "normal" list of
 * words.  See also DICTCOMPRESS.
 *
 */

#include <stdio.h>

#define MAX_LENGTH 80

char* Myfgets (char*, int, FILE*);


main(int argc, char** argv)
{
   char word1[MAX_LENGTH+1];
   char word2[MAX_LENGTH+1];
   char tail[MAX_LENGTH+1];
   int common;

   if (Myfgets (word1, MAX_LENGTH+1, stdin) == NULL)
      exit (0);   /* empty input file */
   else
      printf ("%s\n", word1);

   while (Myfgets (word2, MAX_LENGTH+1, stdin) != NULL) {

      if (isdigit (*word2)) {
         sscanf (word2, "%d%s", &common, &tail);
         strcpy (word1+common, tail);
         word1[common+strlen(tail)+1] = '\0';
         }
      else
         strcpy (word1, word2);

      printf ("%s\n", word1);
      }

   exit(0);
}



/*
 * Myfgets -- Calls fgets() and returns whatever fgets() would have
 *            returned, but with the special added bonus of stripping
 *            off the '\n' that fgets() so graciously includes.
 */

char* Myfgets (char* word, int length, FILE* fp)
{
   char* temp;
   temp = fgets (word, length, fp);
   if (temp != NULL)
      if (*(word+strlen(word)-1) == '\n')
         *(word+strlen(word)-1) = '\0';
   return temp;
}

