// Prak1.cpp : Defines the entry point for the console application.

#ifndef StationsH
#define StationsH

#include "stdio.h"

struct Stations {
 int c;    // counter of stations in array
 char **items;
};


struct Stations *InitStations(){
 struct Stations *s;
  s = (struct Stations*) malloc (sizeof(struct Stations));
  s -> c = 0;
  s -> items = 0;
 return s;
}

void DestrStations(struct Stations *s){
 free(s);
}


int GetStationID(char *s, struct Stations *stat){
 int i;
  for (i=0; i < stat -> c; i++)
   if (strcmp(s, stat -> items[i]) == 0)
     return i;
  return -1;
}


void AddStation(char *s, struct Stations *stat){
 if (GetStationID(s, stat) == -1)
  {
   stat -> c ++;
   stat -> items = realloc(stat -> items, sizeof(char*)*stat->c);
   stat -> items[stat -> c-1] = calloc(strlen(s), sizeof(char));
   strcpy(stat -> items[stat->c-1], s);
  }
}


int ReadStations(char *s, struct Stations *stat){
FILE *f;
int i;
char str1[256], str2[256];

if ((f = fopen(s,"rt")) == NULL) return -1;

 while (!feof(f)) {
  fscanf(f, "%s%s%d",  &str1, &str2, &i);
  AddStation(&str1,stat);
  AddStation(&str2,stat);
  //AddComponent
 }

fclose(f);
return 1;
}


void DestStations(struct Stations *stat){

  int i;

   for (i=0; i < stat->c; i++)
     free(stat->items[i]);

   free(stat->items);
 }



#endif
