Hi, I am relatively new to programming and reading through Kernigan and ritchies book. Everything was going fine untill i encountered this question that has struck me for a while. The question is :

" write a program that copy it's input to it's output replacing each string of one or more blanks by a single blank "

The output presented below prints -1 and as in the exercise i would like that more than one blank is produced as a blank. What am i doing wrong? (probably a lot)


Code:
#include <stdio.h>
#include <stdlib.h>
int main(VOID)
{
int c;
int blanks = 0;
while((c = getchar()) != EOF){
    if(c == ' ')
        putchar(c);
    if(c != ' ')
        putchar(blanks);
}
blanks = c;


printf("%d,%d", c, blanks);