0

Here is a clipping of my code, I know that the segmentation fault happens in the else condition

char* testCase = "AAAAA\0";
string salt = "50";

for (int i = 0; i <= 5; i++)
{

    //Create random 5 character string
    if (testCase[i] == '\0')
    {
        break;
    }
    else
    {
        testCase[i] = 'z';
    }
}

I have no clue why as I've ran several tests such as running printf("%c", testCase[i]); and this prints the element to the console just fine no issue so I'm stuck on why it might be happening in the else condition since I clearly have access to that memory.

1 Answer 1

0

The question is simple, you are trying to change a memory area only read, keep in mind that a string (char *) is immutable in C, I suggest you use an array:

char testCase[] = "AAAAA\0";
1
  • Hi! Thanks for the response, I actually ended up solving it by attacking the issue from a different perspective this was the right solution. Jul 5, 2018 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .