title: segmentation fault while Addition of the station already present in list using c programming
body: <p>I am trying to add a list of stations, wherein if the station name is already present in the single linked list then the station name need not be added. But when I m doing string comparison in findstation function, I am getting a segmentation fault. It's been long time I am debugging. I couldn't find where I am going wrong. It would be a great help if I get to know my mistake. Thanks in advance.  </p>
  
  <pre><code>#include&lt;stdio.h&gt;
      #include&lt;stdbool.h&gt;
      #include&lt;stdlib.h&gt;
      #include&lt;string.h&gt;
  
      struct station
      {
          char station[100];
          struct station *next;
      }destinations;
  
  
      struct station *findStation(struct station *stations,char *station_name);
      void addStation(struct station **stations,char *station_name);
      //void addDestination(struct station *stations, char *station_name);
      void printStations(struct station *stations);
      //void removeStation(struct station **stations, char *station_name);
      int findShortestPath(struct station *stations, struct station *a, struct station *b);
  
      int main()
      {
          struct station *source = NULL;
          char *station_name;
          char c;
          bool quit=false;
          while(!quit)
          {
              scanf("%c",&amp;c);
              switch(c)
              {
                  case 'a':
                  {
                      scanf(" %s", station_name);
                      addStation(&amp;source,station_name);
                      break;
                  }
                  case 'd':
                  {
                      scanf(" %s",station_name);
                      //addDestination(&amp;destinations,station_name);
                      break;
                  }
                  case 'p':
                  {
                      printStations(source);
                      break;
  
                  }
                  case 'q':
                  {
                      quit=true;
                      break;
                  }
                  default:
                      break;
              }
          }
          return 0;
      }
  
  
      struct station *findStation(struct station *stations,char *station_name)
      {
          //returns a pointer to the station with the name station name in the list stations
              struct station *find=NULL;
              printf("h1");
              //printf("%s",station_name);
              //printStations(stations);
              while((stations!=NULL))
              {
                  if(strcmp(stations-&gt;station,station_name)!=0)
                  {
                      printf("%s\n", stations-&gt;station);
                      printf("%s\n", station_name);
                      stations=stations-&gt;next;
                      find=stations;
                      //printf("hello");
                  }
                  else
                  {
                    find=NULL; 
                   // printf("bye");
                    return ;
                  }
              }
              //printStations(find);
              return find;
      }
  
      void addStation(struct station **stations,char *station_name)
      {
          struct station *find;
          struct station *temp;
          temp= (struct station *)malloc(sizeof(struct station ));
          //adds a new station with the name station name to the front of the list stations
          if(*stations== NULL)
          {
              strcpy(temp-&gt;station,station_name);
              temp-&gt;next=NULL;
              (*stations)=temp;
  
          }
          else
          {
              //printf("hi");
              find= findStation(*stations,station_name);
              printStations(find);
              if(find !=NULL)
              {
                  printf("Station station_name already exists.");
                      exit (0);
              }
              else
              {
              strcpy(temp-&gt;station,station_name);
              temp-&gt;next=NULL;
              temp-&gt;next=(*stations);
              (*stations)=temp;
              }
  
          }
  
      }
  
          enter code here
  </code></pre>