# Thread: recursive function with strings

1. ## 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(&#37 ,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);
}```

2. It looks like the function does what you want it to do; if you want to know what your instructor wants it to do, you should ask him/her. (In other words: I'm not sure either; maybe your instructor wants 'z' to cycle back to 'a'.)

3. I can't ask the instructor.So for this reason i am asking here if anyone understand something other? I was thought also something about cycle arithmetic with characters and the USE of modulo(&#37 like in cryptography.Do you understand me?

4. I can't ask the instructor.
You cannot clarify questions with your instructor?

So for this reason i am asking here if anyone understand something other?
As tabstop pointed out, there are at least two interpretations of the question:
a) Rotate the characters with respect to their positions in the string.
b) Rotate the value of the characters with respect to their positions in the alphabet.

Additionally, the direction of the rotation is left unspecified (perhaps it does not matter).

5. Originally Posted by laserlight
You cannot clarify questions with your instructor?

As tabstop pointed out, there are at least two interpretations of the question:
a) Rotate the characters with respect to their positions in the string.
b) Rotate the value of the characters with respect to their positions in the alphabet.

Additionally, the direction of the rotation is left unspecified (perhaps it does not matter).
thanks.So we can't say that is something like this I said (modulo....).
These a) and b) that you tell me i can make them.

and i can't ask my "instructor" because i don't know him.This exercise i found it on the web from a university

6. So we can't say that is something like this I said (modulo....).
You can use modulo to cycle through the alphabet and go from 'z' -> 'a', but it is probably easier just to check for 'z' and then assign 'a'.

and i can't ask my "instructor" because i don't know him.This exercise i found it on the web from a university
I suspect that your interpretation of the question is correct since "character cycle" seems to imply cycling through the alphabet. However, since this is not an actual assignment, you might as well attempt both interpretations.

Likewise, you should feel free to make your own input/output requirements and experiment. There is no need to ask us to set the question for you, you can set it yourself and check with us to verify that your solution is a good one (or otherwise).