how to fix "Segmentation fault (core dumped)"--error
how to fix "Segmentation fault (core dumped)"--error
Erm... By fixing the bug that causes it?
Seriously, a segmentation fault can be caused by countless of things: buffer overflows, dereferencing dangling pointers, double frees, writing to read-only memory and loads more.
You should really post the code or find out what causes the segmentation fault. If you program with Linux run the program with valgrind and you'll get some useful information.
this is the function which causes the problem I have even found the line which gives me the error
Code:set<int> eTransition(set<int> s) { set<int> eSet; set<int>::iterator itTemp; queue<int> que; int pop; set<int> processed; for(it = s.begin();it!=s.end();it++) { itTemp = eSet.find(*it); if(itTemp != eSet.end()) { // element is in the set so continue without executing anything continue; } //element is not in the set so insert it in the set and find its etransitions que.push(*it); eSet.insert(*it); while(!que.empty()) { pop=que.front(); que.pop(); int i; for(i=0;i<nfaTransition.size();i++) { if(nfaTransition[i].state==pop) { break; } } for(int j=0;j<nfaTransition[i].linke.size();j++) { itTemp = eSet.find(nfaTransition[i].linke[j]); if(itTemp == eSet.end()) { que.push(nfaTransition[i].linke[j]); //if I comment this line I don't get error eSet.insert(nfaTransition[i].linke[j]); } } } } return(eSet); }
and how can I start going with Valgrind?
The Valgrind website sounds like a good starting point.
At this point i will be equal to nfaTransition.size().Code:for(i=0;i<nfaTransition.size();i++) { if(nfaTransition[i].state==pop) { break; } }
i is still equal to nfaTransition.size(). Which means you're using nfaTransition[nfaTransition.size()]. This is illegal: the range is from 0 to .size()-1.Code:for(int j=0;j<nfaTransition[i].linke.size();j++) { itTemp = eSet.find(nfaTransition[i].linke[j]); if(itTemp == eSet.end()) { que.push(nfaTransition[i].linke[j]); //if I comment this line I don't get error eSet.insert(nfaTransition[i].linke[j]); } }