recursive function with strings
I have to write this recursive function:
write a recursive function called shift which takes a string and rotates each character cycle one position at the time.The problem is that i don't understand what the problem says. What should i do?
i think that i should add +1 in each character so the character goes to the next ascii(example if we have abc now becomes bcd) but i am not sure what the problem ask?
OR
what about cycle arithmetic with characters and modulo(%) ,like in cryptography
my code for the first thought
Code:
#include <stdio.h>
#include <string.h>
#define FIRST_ASC ' '
#define LAST_ASC '-'
void shift(char str[],int i);
int main(void){
int i=0;
char str[]="hello world there";
shift(str, i);
printf("%s\n", str);
char c;
c='a';
c=c+1;
printf("%c\n", c);
return 0;
}
void shift(char str[], int i){
int p=i;
if(str[p]=='\0') return;
/*if((str[p]>= FIRST_ASC) && (str[p]<=LAST_ASC)) i didn't need this*/
str[p]=(str[p] + 1);
shift(str, ++p);
}