CodingInterviews icon indicating copy to clipboard operation
CodingInterviews copied to clipboard

a%20b%20c%20d *** stack smashing detected ***: ./004 terminated 已放弃 (核心已转储)

Open MrLinNing opened this issue 7 years ago • 0 comments

`` #include

using namespace std;

#define __tmain main

class Solution { public: void replaceSpace(char *str,int length) { int i, j; int count = 0; int len = length; for(int i = 0; i < length; i++) { if(str[i] == ' ') { count++; } }

    len = length + count * 2;
    for(i = length - 1, j = len - 1;
        i >= 0 && j >= 0;)
    {
        if(str[i] == ' ')
        {
            str[j--] = '0';
            str[j--] = '2';
            str[j--] = '%';
            i--;
        }
        else
        {
            str[j--]  = str[i--];
        }
    }
    str[len] = '0';

}

};

int __tmain( ) { char str[10 + 1] = "a b c d";

Solution solu;
solu.replaceSpace(str, 10);

cout <<str <<endl;

return 0;

} `` char str[10 + 1] = "a b c d"; 换成: char str[7 + 1] = "a b c d"; 报错: a%20b%20c%20d *** stack smashing detected ***: ./004 terminated 已放弃 (核心已转储)

MrLinNing avatar Apr 02 '18 06:04 MrLinNing