First, you must make sure that your function "Recursion" can work to a single line. Your function "Recursion" may be declared like this:
//source must have pointed to storage space of the line and the
//storage space of line must be not read-only. As we know "dogs" is
// a constant value you can't change.
int Recursion(char *source,int length);
Inputting the string "dogs" to the Recursion, the output must be the "sgod".
Then, you can read each line of the file and input them to this function Recursion so that you can get the result you want.
I think the function Recursion may have bugs or you are failed to read line from the file. If you can give me detail code about function Recursion or the module of reading file, it is easy to figure out the error.
You are using the function getchar() instead of reading line from the file. So 'EOF' is not right and should be '\n'. You also should't using while in Recursion because it is already a recursion function. So the right code is following:
void Recursion()
{
int c;
if((c = getchar()) != '\n')
{
Recursion(c);
printf("%c",c);
}
else
return;
}
I think your code is not good. In my opinion, the function to reverse the string does't need Recursion and just likes this:
int Recursion(char *source,int length);
so that you can divide the program into separate modules---read line and reverse. Thus the main function just likes this:
int main()
{
int fd = open();
while(1)
{
// 1.read line
....
//2. is EOF?
break;
//3. reverse line
Recursion(line,strlen(line));
}
}
I hope that can help you.