title: C++ RasPi - Segmentation fault while in endless loop
body: <p>So I run an DS18S20 with an LCD Display.</p>
  
  <p>I'm measuring my Room Temperature and displaying it on the LCD.</p>
  
  <p>In said endless loop, I'm getting a Segmentation Fault after it ran 5-6 times. I've read that it must be a variable and got the suspicion that it's in my getTmp() function but don't know how to fix it.</p>
  
  <p>I've been learning C++ for two weeks now and need your help.</p>
  
  <p>Thank you in advance.</p>
  
  <p>My Code: </p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include &lt;wiringPi.h&gt;
  #include &lt;lcd.h&gt;
  #include &lt;unistd.h&gt;
  using namespace std;
  #define ever (;;)
  //USE WIRINGPI PIN NUMBERS
  #define LCD_RS  25               //Register select pin
  #define LCD_E   24               //Enable Pin
  #define LCD_D4  23               //Data pin 4
  #define LCD_D5  22               //Data pin 5
  #define LCD_D6  21               //Data pin 6
  #define LCD_D7  14               //Data pin 7
  void getTmp(string *y)
  {
      ifstream file("/sys/bus/w1/devices/10-00080366745a/w1_slave");
      string f[2];
      if (file.is_open())
      {
  
          for (int i = 0; i &lt; 2; ++i)
          {
              getline(file, f[i]);
          }
      }
      string s = f[1];
      bool x = true;
      int i3 = 0, i2 = 0;
      while (x)
      {
          if (i2 &lt;= 4 &amp;&amp; i2 &gt; 0)
          {
              y[i2 - 1] = s[i3];
              ++i2;
          }
          if (i2 &gt; 4)
          {
              x = false;
          }
          if (s[i3] == '=')
          {
              i2 = 1;
          }
          ++i3;
      }
  }
  
  int main()
  {
      unsigned int microseconds = 5000;
      string b[4];
      string *y = b;
      int lcd;
      wiringPiSetup();
      const char *tmp;
      for ever
      {   
          getTmp(y);
          string t = "Temp = "+b[0]+b[1]+"."+b[2]+b[3]+"°C";
          tmp=t.c_str();
          lcd = lcdInit (2, 16, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0);
          lcdPuts(lcd, tmp);
          cout &lt;&lt; tmp &lt;&lt; endl;
          usleep(microseconds);
      }
      return 0;
  }
  </code></pre>