C语言,字符串 逆序输出问题

自己写了一段逆序输出的代码,但是运行没有结果

 #include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[100];
    int i;

    i = 0;                               
    while ((a[i]=getchar())!='\r')      /*将输入的字符依次保存在a数组中,并递增i,记录字符串长度*/
    {
        i++;
    }

    for (; i >= 0; i--)
    {
        printf("%c", a[i]);         /*倒序依次输出字符*/
    }

    system("pause");
    return 0;
}

规定的是遇到\r(回车)就中止循环,但是实际运行时输入回车后就直接换行了,并没有中止循环,请问是哪里出问题了,另,我的思路有问题吗

 while ((a[i]=getchar())!='\n') 
看看