#include <stdio.h>

   typedef 
   struct {
      char *name;
      int  code;
   } item;

   item sexlist[] = {
   {"M",1},
   {"F",2},
   {"K",2},
   {"-",9},
   };

   int SEXMAX = sizeof(sexlist) / sizeof (item);



   item marlist[] = {
   {"-",9},
   {"G",2},
   {"UG",1},
   {"E",4},
   {"S",5},
   {"F",6},
   };

   int MARMAX = sizeof(marlist) / sizeof (item);


item rellist[] = {
   {"Adoptivdatter",30},
   {"barn",30},
   {"Barnebarn",60},
   {"Broder",151},
   {"D",32},
   {"Datter",32},
   {"Datterdatter",62},
   {"Datters›n",62},
   {"Deres Datter",32},
   {"EL",3200},
   {"Enslig losjerende",3200},
   {"F›deraadskone",3400},
   {"F›deraadsmand",3400},
   {"Fader",121},
   {"Fange",3774},
   {"Fattiglem",3771},
   {"FL",3300},
   {"Fosterbarn",30},
   {"Fosterdatter",38},
   {"Fosters›n",37},
   {"Gj‘tergut",5000},
   {"Hans Datter",32},
   {"Hans Kone",22},
   {"Hf",10},
   {"Hm",22},
   {"Husfader",10},
   {"Husmor",22},
   {"Huusfader",10},
   {"Inderst",3100},
   {"Kaarekone",3400},
   {"Kaaremand",3400},
   {"Kaarenke",3400},
   {"Kaarkone",3400},
   {"Kaarmand",3400},
   {"Kaartager",3400},
   {"L‘gdslem",3771},
   {"Logerende",3200},
   {"Losjerende",3200},
   {"Moder",122},
   {"Onkel",131},
   {"Patient",3771},
   {"Pleiebarn",30},
   {"Pleiedatter",38},
   {"Pleies›n",37},
   {"S",31},
   {"S›n",31},
   {"S›nnedatter",62},
   {"S›nnekone",36},
   {"S›nnes›n",61},
   {"S›skende",150},
   {"S›ster",152},
   {"S›sters›n",42},
   {"S›stre",152},
   {"Skoleelev",3372},
   {"Stedatter",34},
   {"Svigerbroder",155},
   {"Svigerdatter",36},
   {"Svigerfader",125},
   {"Svigermoder",126},
   {"Svigers›n",35},
   {"Svigers›ster",156},
   {"Tjener",5000},
   {"Tjenestepige",5000},
     
   };
   int RSTDMAX = sizeof(rellist) / sizeof (item);

   int sexcode(char *s);
   int marcode(char *s);
   int rstdcode(char *s);

   int sexcode(char *s)
   {
      int i;
   
      for (i=0;((i<SEXMAX)&& (strcasecmp(s,sexlist[i].name)!=0));i++);
      if (i>=SEXMAX) 
         return 9;
      else 
         return sexlist[i].code;
   }

   int marcode(char *s)
   {
      int i;
   
      for (i=0;((i<MARMAX)&& (strcasecmp(s,marlist[i].name)!=0));i++);
      if (i>=MARMAX) 
         return 9;
      else 
         return marlist[i].code;
   }

   int relcode(char *s)
   {
      int i;
   
      for (i=0;((i<RSTDMAX)&& (strcasecmp(s,rellist[i].name)!=0));i++);
      if (i>=RSTDMAX) 
         return -1;
      else 
         return rellist[i].code;
   }

   int printrel(char *filename)
   {
      int i;
      FILE *fp;
   
      if ((fp=fopen(filename,"w"))==NULL) {
         printf("Could not open %s for writing\n",filename);
         exit(-1);
      }
   
      for (i=0;i<RSTDMAX;i++)
         fprintf(fp,"%s\t%d\n",rellist[i].name,rellist[i].code);
      fclose(fp);
      return i;
   }