Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrLinNing opened this issue Apr 2, 2018 · 0 comments

Comments

@MrLinNing
Copy link

``
#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
已放弃 (核心已转储)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant