Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Exit Code 139 - what's wrong?

This V returns for me exit code 139 - which means it's has a undefined behaviour. I really don't understand why. This function returns the longest possible string from K consecutive strings.

std::string longestConsec(std::vector<std::string> &strarr, int k){

    for(int i=0;i<strarr.size();i++){
       std::cout<<strarr[i]<<std::endl;
    }

    int maxi{}, m{};
    std::string result{}, r{};

    for(int i = 0;i<=strarr.size()-k;i++){  
        for(int j = i;j<i+k;j++){
            m+=strarr[j].length();
            r+=strarr[j];
        }
        if(m>maxi){ 
            result = r;
            maxi = m;
        }

        m = 0;
        r = "";
    }

    return result;
}

Comments