Unable to figure out the K&R 1.19 exercise reverse (s) func

I am trying to figure out the K&R 1.19 exercise, hence, created my pattern of the solution:

#include <stdio.h> #define MAXLINE 40 int reverse(char [],int); int mgetline(char [],int);  int main() {     char line[MAXLINE];     char longest[MAXLINE];     int max,len;     max=0;     while ((len=mgetline(line,MAXLINE))>0)         if (len>max) {             max=len;             reverse(line,max);         }     printf("\n%s\n",line); }  int mgetline(char s[],int lim) {     int i,c;     for (i=0;i<lim-1&&(c=getchar())!=EOF&&c!='\n';++i)         s[i]=c;     if (c=='\n') {         s[i]=c;         ++i;     }     s[i]='';     return i; }  int reverse(char d[],int newlim) {     char tmp[newlim-2];     int i,j;     for (i=0;(tmp[i]=d[i])&&i<=(newlim-2);++i)     j=i;     i=0;     while (j!=0) {         d[i]=tmp[j];         --j;         ++i;     }     if (j=0) {         d[i+1]='\n';         ++i;     }     d[i]='';     return 0; } 

When I try to run it:

pi@host:~/new$   cc reverse.c pi@host:~/new$   a.out aaaabbbbcccc  <> pi@host:~/new$      

Why am I not getting the line printed out? Does the reverse function correct?