S
sathyashrayan
Exercise 1-9
"Write a program to copy its input to its output, replacing each
string of one or more blanks by a single blank"
I got the following solution from the net
<url>
http://users.powernet.co.uk/eton/kandr2/krx109.html
</url>
#include <stdio.h>
int main(void)
{
int c;
while ((c = getchar()) != EOF) {
if (c == ' ') {
putchar(c);
while((c = getchar()) == ' ' && c != EOF)
;
}
if (c == EOF)
break; /* the break keyword is mentioned
* in the introduction...
* */
putchar(c);
}
return 0;
}
When I run this code the program does not terminate. It keeps
getting the input from the stdin. When I type more than one blank space
the program simply prints the set of char as it is including more than
one blank. Is the program wrong or I am missing something?
--
"combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan AT gmail DOT com
"Write a program to copy its input to its output, replacing each
string of one or more blanks by a single blank"
I got the following solution from the net
<url>
http://users.powernet.co.uk/eton/kandr2/krx109.html
</url>
#include <stdio.h>
int main(void)
{
int c;
while ((c = getchar()) != EOF) {
if (c == ' ') {
putchar(c);
while((c = getchar()) == ' ' && c != EOF)
;
}
if (c == EOF)
break; /* the break keyword is mentioned
* in the introduction...
* */
putchar(c);
}
return 0;
}
When I run this code the program does not terminate. It keeps
getting the input from the stdin. When I type more than one blank space
the program simply prints the set of char as it is including more than
one blank. Is the program wrong or I am missing something?
--
"combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan AT gmail DOT com