#include <stdio.h>
struct Liste {
  long Nr;
  char Eintrag[40];
  struct Liste *Next;
};
struct Liste *Kopf,*Ende;

long atol(char *);
char Eingabe[40];

void Init(void)
{
  Kopf = (struct Liste *)malloc(sizeof(struct Liste));
  Ende = (struct Liste *)malloc(sizeof(struct Liste));
  Kopf->Nr=0; Kopf->Eintrag[0]=0x0;
  Kopf->Next=Ende; Ende->Next=Ende; Ende->Nr=-1;
}
void Einfuegen(long nr,char *inhalt)
{
  struct Liste *akt=Kopf,*new;
  new = (struct Liste *)malloc(sizeof(struct Liste));
  if( new ) {
    strcpy(Ende->Eintrag,inhalt);
    while( strcmp(inhalt,akt->Next->Eintrag) > 0 ) akt=akt->Next;
    new->Next=akt->Next; akt->Next=new;
    new->Nr=nr;
    strcpy(new->Eintrag,inhalt);
  }
}
long Suchen(char *eintrag)
{
  struct Liste *search=Kopf;
  strcpy(Ende->Eintrag,eintrag);
  while( strcmp(eintrag, search->Eintrag) > 0 ) search = search->Next;
  if( strcmp(eintrag,search->Eintrag) ) return Ende->Nr;
  return search->Nr;
}
main() {
  long anz=0,ret;
  Init();
  if( Kopf && Ende ) {
    while( anz < 10 ) {
      printf("Eingabe des %d.ten Eintrags: ",anz+1);
      gets( Eingabe );
      Einfuegen(anz++,Eingabe);
    }
    for( anz=0; anz<3; anz++ ) {
      printf("Suchen nach welchem Datensatz (Zeichenkette) ? ");
      gets( Eingabe );
      ret=Suchen(Eingabe);
      if( ret != -1 )
        printf("Gefunden. Nr. des Datensatzes: %d\n",ret+1);
      else
        printf("Nicht gefunden\n");
    }
  }
}
