#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
string a = "bob";
string b = "steve'";
for (int c = 0, n = strlen(b); c < n; c++)
{
a[c] = b[c];
if (a[c] == '\0')
{
a[c+1] = '\0';
a[c] = b[c];
}
if (b[c] == '\0')
{
a[c] = '\0';
break;
}
}
printf("%s", a);
}
The error happens at the line that says a[c] = b[c] first, or the 12th line of code. The point of the code is to try and change string a to string b. However, it seems that I cant make two characters of arrays equal. Is there some way this is possible?
To make the those strings the same, I simply tried making their characters equal. It resulted in a Segmentation fault (core dumped).