C++ Learning Community Forum
August 01, 2010, 02:51:07 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Segmentation fault errors with string class methods on linux with "c++" compiler  (Read 880 times)
sasidhar.o
N00b!!1
*
Posts: 1


View Profile
« on: July 10, 2009, 07:43:33 AM »

Hi! Everybody,

I have the following function written for linux 32-bit "c++" compiler, which gives the error underneath the code.
Can you please explain why this could be and how can I correct it?

This code works fine for some calls and for the others (especially when called from other classes from the class in which this method is defined) not. Notable thing is that the actual string is always printed by the line-

   cout<<"Actual sequence : "<<this->sequence<<endl;

as follows -

Actual sequence : CGGCCGGCTTGGAGAGTAACTCAA.

But the next immediate line that calls - string.substr(int,int) fails in some cases with a -"segmentation error".


Seeking emergency help please.


code:
------
        string getTrimmedSequence(int start, int end){
                string line;

                string line1=getFirstLine();
                line.append(line1);
                line.append("\n");

                cout<<"\nSequenceData : getTrimmedSequence("<<start<<","<<end<<") :"<<endl;
                cout<<"Actual sequence : "<<this->sequence<<endl;
                string line2=this->sequence.substr(start,end);
                cout<<"Trimmed portion : "<<line2;

                line.append(line2);
                line.append(line1);

                return line;
        }

error:
---------

SequenceData : getTrimmedSequence(0,2) :
Actual sequence : CGGCCGGCTTGGAGAGTAACTCAA
Segmentation fault


Regards,
Sasidhar.O     
Logged
charlie
Is the meadow on fire?
Dr. of C++ology
****
Posts: 730


CsGYh8AacgY


View Profile
« Reply #1 on: July 12, 2009, 01:21:37 AM »

Can't tell from what you posted.

I'd assume that the this object is slightly corrupted. I also assume it's too late now since it was an emergency a couple days ago, but you could post the real function definition as well as the code that calls it (including information/code on how the object that it is called on is created).
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!