#include <stdio.h>
/* copy input to output, replace each string of one or more blanks by a single blank */
int main()
{
int c, n1 = 0;
while ((c = getchar()) ! = EOF) {
while (c == ' ')
++n1;
n1 = ' ';
putchar(c);
printf( "%d %n1", c, n1);
}
}
I need help with the above code because it won`t compile, and don`t know why. Thanks
The (c = getchar() part is probably correct (so = not ==).
He's using getchar() to obtain a value and store it in c which is then compared to EOF, a value supplied via macro in stdio.h
See http://www.cplusplus.com/reference/cstdio/
include <stdio.h>
/* copy input to output, replace each string of one or more blanks by a single blank */
int main()
{
int c, x;
while ((c = getchar() != EOF))
{
if (c == ' ') {
while ( scanf ( "%c", &x ) == 1 ) // Read white space
; // Do nothing
putchar(' '); // Replace with single blank
}
putchar (c);
}
return 0;
}
It won`t work properly though, anyone else can write it?