I am getting a SIGABART error.. i cant find why.

help

#1

#include
using namespace std;
int main()
{

int T;
cin>>T;
string s[T];int N[T],M[T];
for(int i=0;i<T;i++)
{
    cin>>s*;cin>>N*>>M*;
    
}
for(int i=0;i<T;i++)
{
    for(int j=N*;j<M[T];j++)
    {
        string s1=s*.substr(j,1);string s2=s*.substr(j+1,1);
        if(s1.compare(s2)==-1){s*.erase(j+1,1);s*.insert(j,s2);}
    }
}
for(int i=0;i<T;i++)
{
    cout<<endl<<s*;
}
return 0;

}


#2

Idk what is the question but M[T] should be M* I guess(in condition of for loop)… If not… share the question link.


#3

You are getting SIGABART because the value of M[T] goes beyond the string length and hence you cant compute substring of the string. In some Compilers, M[T] would be 0 by default. I checked on Codechef’s Compiler it was random more than 32K and in your test case string length would be less, hence SIGABART. (Out of range). Mostly, instead of M[T], it would be M*. Just make sure N*, M* it doesn’t go beyond String length(s*.size()).


#4

thanku it should have been M*:slight_smile:


#5

welcome :smiley: