Cannot find the error on my program ( verry basic C stuff )



Hi folks,

I'am learning C programming from ANSI_C Reference Manual of Kernighan & D.Ritchie .
I'm still working on the tutorial chapter , in have some issues with exercice 1-18 .

The goal is to write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.

Here's my source code :

**********************

/* Remove trailing blanks and tabs from each line
** not worked yet on removing tabs
*/

#include <stdio.h>

#define MAXLINE 1000 /* max input line length */
#define IN 1
#define OUT 0

/* function prototypes */
int getline (char line[], int maxline);
void clean (char line[], char cleaned[]);

/* prints input lines after removing trailing blanks and tabs */
int main(void)
{
char line[MAXLINE]; /* current line */
char cleaned[MAXLINE]; /* cleaned line */

while (getline (line, MAXLINE)){
clean (line, cleaned);
printf ("\n%s", cleaned);
}
}


/* get new line into an char array */
int getline(char line[], int lim)
{
int c, i;

for (i=0; i < lim - 1 && ((c = getchar()) != EOF) && (c != '\n'); ++i)
line[i] = c;
if (c == '\n'){
line[i] = c;
++i;
line[i] = '\0';
return 1;
}
if (c == EOF)
return 0;

}

void clean(char line[], char cleaned[])
{
int space;
int i;

if (line[0] == ' ')
space == IN;
else
space == OUT;

for (i=0; line[i] != '\0'; ++i){
if (space == OUT)
if (line[i] != ' ')
cleaned[i] = line[i];
else if (line[i] == ' '){
space == IN;
cleaned[i] = line[i];
}
else if (space == IN)
if (line[i] != ' '){
cleaned[i] = line[i];
space == OUT;
}
else if (line[i] == ' ')
;
}
cleaned[i] = line[i];
}

**************************************


The output gives me 8 whatever the input was .
If somebody can help me to resolve this problem it would be great , i need just to find where's the error not to get the solution to this probleme as i have the solution book .

Thx in advance and sorry for my poor english

Chakib .B
.