I am trying to solve this problem from K&R book.
Write a function reverse(s) that reverses the character string s. Use it to
write a program that reverses its input a line at a time.
My solution
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXLINE 10
void reverse(char r[], char s[]);
int main(void) {
int i,c;
char line[MAXLINE];
char reversed[MAXLINE];
for (i=0; i < MAXLINE && (c=getchar())!='X' && c!='\n'; ++i)
line [i] = c;
reverse (reversed,line);
printf ("%s", reversed);
return 0;
}
void reverse (char r[], char s[])
{
int i=0;
for (i=0; i<=10; i++)
r[i]=0;
while (i <= 10 && s[i] != '\0')
{
r[10-i] = s[i];
}
++i;
}
The problem is...am not getting any output. I am guessing it's a concept problem with me but I am unable to figure it out. Any help please?