# Error of "\*\*\* Break \*\*\* segmentation violation"

**URL:** <https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763>\
**Category:** Newbie\
**Created:** [July 11, 2022, 11:37pm UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763 "2022-07-11T23:37:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [July 11, 2022, 11:37pm UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763/1 "2022-07-11T23:37:18Z")

</div>

my program is giving the Segmentation violation error. Please could you help me figure the error.

```auto
ifstream in;
    in.open("Temperature01-12-2021-09-12-2021.txt");
    int lincent;
    float date_index;
    double temperature;
    vector <float> date;
    vector <float> temp;
    ULong64_t first_timestamp;
    ULong64_t last_timestamp;
    TCanvas* mianCanvas = new TCanvas("miancanvas");
    while(!in.eof())
    {
        in>>date_index>>temperature;
        lincent++;
        date.push_back(date_index);
        temp.push_back(temperature);
    }
    printf("%d", lincent);
    TGraph* graph = new TGraph(lincent);
    graph->SetMarkerStyle(7);
    graph->SetMarkerColor(kRed);
    graph->SetLineColor(kRed);
    graph->GetXaxis()->SetTimeDisplay(1);
    graph->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M:%S %F 1970-01-01 00:00:00");
    first_timestamp = (date.data())[0];
    last_timestamp = (date.data())[lincent-1];
    TTimeStamp first_ts(first_timestamp);
    TTimeStamp last_ts(last_timestamp);
    for(int i = 0; i < lincent; i++)
    {
      graph->SetPoint(i, (date.data())[i], (temp.data())[i]);
    }
    graph->SetTitle(Form("%d-%d", first_ts.GetDate(), last_ts.GetDate()));
    graph->GetXaxis()->SetTitle("Time");
    graph->GetYaxis()->SetTitle("Current (A)");

    graph->Draw("ALP");
    return 0;

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 12, 2022, 4:49am UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763/2 "2022-07-12T04:49:13Z")

</div>

```auto
        // ...
        lincent++;
        cout << lincent << endl;
        // ...

```

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [July 12, 2022, 5:21am UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763/3 "2022-07-12T05:21:13Z")

</div>

it didn’t solve the issue. Still shows same **Break Segmentation error**

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 12, 2022, 5:32am UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763/4 "2022-07-12T05:32:04Z")

</div>

Read the output of that and find the problem.

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [July 12, 2022, 10:33am UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/50763/5 "2022-07-12T10:33:53Z")

</div>

I guess the problem is that you didn’t initialize your variable:

```auto
    int lincent;
    float date_index;
    double temperature;

```

should be

```auto
    int lincent = 0;
    float date_index = 0.0;
    double temperature = 0.0;

```

(for the float and double, it doesn’t matter because you are reading them later from file, but it’s good practice to always define your variables).
