I was writing the program for what appeared a fairly simple problem: Print a string in reverse order using recursion. My code is as follows. The strange thing is that I get Segmentation Fault errors no matter what I do. Any help is greatly appreciated. I'm on Linux, by the way.
Code:/* Reverse a string using recursion */ #include <stdio.h> void rev_string(char *c) { if(*c != '\0') { rev_string(c++); printf("%c", *c); } } void get_line(char str[]) { int i=0; char c; while(c=getchar() != '\n') { str[i++] = c; } str[i] = '\0'; } int main() { char str[100]; get_line(str); rev_string(str); printf("\n"); return 0; }