Testing solution to K&R C exercise 1-18 doesn't work
<p>Below is the solution to exercise 1-18 mentioned in the C Answers Book, The exercise asks for the following: Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.</p>

<p>I'm trying to test it on cygwin for windows as follows:</p>

<pre><code>./ex1_18.exe &lt;text.txt &gt;t.txt
</code></pre>

<p>but the resulted file (t.txt) is a typical copy of the original file (text.txt) with the same trailing blanks and tabs.
what is the problem?</p>

<p>Thanks in advance.</p>

<p>this is the C answers book's solution (with some changes to function names):</p>

<pre><code>#include &lt;stdio.h&gt;
#define MAXLINE 1000

int getln(char Line[], int maxline);
int remov(char s[]);

main()
{
    char line[MAXLINE];

    while(getln(line, MAXLINE)&gt;0)
        if(remov(line)&gt;0)
            printf("%s", line);
        return 0;

}

int remov(char s[])
{
    int i;
    i=0;
    while(s[i]!='\n')
        ++i;
    --i;
    while(i&gt;=0 &amp;&amp; (s[i]==' ' || s[i] == '\t'))
        --i;
    if(i&gt;=0){
        ++i;
        s[i]='\n';
        ++i;
        s[i]='\0';

    }
    return i;
}

int getln(char s[], int lim)
{
    int c, i, j;
    j=0;
    for(i=0; (c=getchar()) != EOF &amp;&amp; c!= '\n'; ++i)
        if(i&lt; lim -2){
            s[j]=c;
            ++j;
        }
    if(c=='\n'){
        s[j]=c;
        ++j;
        ++i;
    }
    s[j]='\0';
    return i;
}
</code></pre>