I'm new here and new in programming field too.
I was given a task to reverse a string using recursion and I build a program for it. But I'm not sure whether it is using recursion or not? Here's the code:
#include <stdio.h>
#include <string.h>
void reverse(char, long);
int main(){
char i[100];
long c;
gets(i);
c = strlen(i);
reverse(i,c);
return 0;
}
void reverse(char x[100], long y){
printf("%c", x[y-1]);
if (y>=0) {
reverse(x, y-1);
}
}
I just want to know whether this program is using recursion for reversing the string or not?
y >= 0looks bad and you should only decrementyonce.fcall functiongwhich callsf) then that's the very definition of recursion.