I'm trying to write a function that takes in an arbritrary string and changes all the letters to the next letter in the alphabet (eg. "John" to "Kpio"). My function works if I define the string str (eg. char str[] = "John"), but not when I leave it as arbitrary; instead I get a segmentation fault (core dumped) error.
I've tried using pointers instead by adding *str to everything, but this didn't work and I'd rather the solution didn't use pointers since I'm still unfamiliar with them.
#include <stdio.h>
/*declare function*/
void letter( char str[] ) {
int i = 0;
while ( str[ i ] != 0 ) {
str[i] += 1;
printf("%c", str[i]);
i++;
}
}
/*call function with input "John"*/
int main( void ) {
letter( "John" );
return 0;
}