I have written a beginner-level program to recursively reverse a string. I use a variable with file scope and strlen(). However, the task seems to be not to use any of those or pointers, and the reverseString function should only receive an array. Is it possible to write a recusive function with such conditions?
#include <stdio.h>
#include <string.h>
void reverseString(char[]);
int i = 0;
int main()
{
char word[100];
printf("Write something: ");
scanf("%s", word);
printf("What you wrote reversed is: ");
reverseString(word);
return 0;
}
void reverseString(char string[]) {
if (string[i] != '\0') {
++i;
printf("%c", string[strlen(string) - i]);
reverseString(string);
}
}