I have to implement a recursive function. But I got stuck there.
The function I write is like that:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int strlenRecursive(char* str) {
if (str == '\0')
return 0;
else
return strlenRecursive(str-1);
}
int main() {
char buffer[256];
printf("Enter a string and I will tell you the length (CTRL-Z to quit)\n");
while (scanf("%s", buffer) != EOF) {
printf("The Length of '%s' is %d\n", buffer, strlenRecursive(buffer));
}
fflush(stdin);
getchar();
}
I have no idea on how to solve it which took me nearly one week!.
Thanks