I'm writing a program in C that goes through a string and replaces every alphabetical letter with the letter 13 letters after it in the alphabet (so a Caesar cipher, basically).
I'm relatively new to C and I'm having a difficult time working with strings. My issue at the moment is that when I initialize a new string in line 2, for some reason, the string already has random stuff in it. I know this because when I print the string in line 3, I see 3 random characters (and they're not always the same, they change every few code executions).
Here's the relevant part of my code:
printf("The original string is %s\n", src);
char *result = malloc(strlen(src) * sizeof(char) + 1);
printf("Right off the bat, the result string looks like: %s\n", result);
for (int index = 0; index < strlen(result); index++)
{
result[index] = "\0";
}
printf("Now, the result string looks like: %s\n", result);
My loop in lines 4-7 attempts to empty the string by setting every character in it equal to null. Even more strangely, this loop doesn't work, because when I print the string again in line 8, it's still not empty. Now, though, instead of having random junk in it, it's got the letter "j" repeated 4 times in the first 4 spaces of the allocated space.
I'd really appreciate any help with this. Thanks.