Why segmentation error?

Write your question here.

I at the moment trying create a graph based from elements in a 2d char array..

But things aren't working as smoothly as i hoped.


The way i create my nodes is like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
createGraph()
{
  cout << "I was called: " << graph.size() << endl;

  for (int row = 0; row < getRow(); row++) {
    for (int col = 0; col < getCol(); col++) {
         Edge edge;
         edge.Element = getChar(row,col);
         edge.label = make_pair(row,col);
         auto before = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(row-1,col)));
         auto next = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(row+1,col)));
         auto down = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(row,col-1)));
         auto up = std::find_if(graph.begin(), graph.end(),find_neigbour(make_pair(row,col+1)));
         if(isspace(graph[before-graph.begin()].Element)){
           if(before != graph.end())
           {
             cout << "lol" << endl;
              Arcs arc;
              arc.me = &edge;
              cout << edge.Element << endl;
              arc.neighbour = &graph[before - graph.begin()];
              cout << graph[before-graph.begin()].Element << endl;
              edge.neighbours.push_back(arc);
              cout << " before- arc - added" << endl;
           }
         }
         if(isspace(graph[next-graph.begin()].Element)){
           if(next != graph.end())
           {
              Arcs arc;
              arc.me = &edge;
              arc.neighbour = &graph[next - graph.begin()];
              edge.neighbours.push_back(arc);
              cout << "-next arc - added" << endl;
           }
         }
         if(isspace(graph[up-graph.begin()].Element)){
           if(up != graph.end())
           {
              Arcs arc;
              arc.me = &edge;
              arc.neighbour = &graph[up - graph.begin()];
              edge.neighbours.push_back(arc);
              cout << "up - arc - added" << endl;
           }
         }
         if(isspace(graph[down-graph.begin()].Element)){
           if(down != graph.end())
           {
              Arcs arc;
              arc.me = &edge;
              arc.neighbour = &graph[down - graph.begin()];
              edge.neighbours.push_back(arc);
              cout << " down - arc - added" << endl;
           }
         }
    }
  }

  cout << "I end: " << graph.size() << endl;

}
Last edited on
It seems like that the segmentation error occurs when isspace is called.
Here is an article about segmentation fault, maybe it helps.

http://www.cprogramming.com/debugging/segfaults.html
Topic archived. No new replies allowed.