Hi,
NOTE:
If this thread is not acceptable for DMG admins, please delete.
Hi All C gurus,
Since I am studying C as instructed, I am encountering situations
where I may need help to clarify things a bit. I studying:
"The C programming language" (Kernighan & Ritchie)
as suggested by KatolaZ.
On page Page 34 Exercise 1-9
"Write a program to copy its input to its output, replacing each
string of blanks one ore more blanks by a single blank."
I wrote the following, tested it, and it seems to work, but I think it is
too complicated. Any suggestions?
--------------------------
#include <stdio.h>
int main()
{
int c, d = 0;
while ((c = getchar()) != EOF) {
if (c != ' ') {
d = 0;
putchar(c);
}
if (c == ' ' && d == 0) {
putchar(c);
d = 1;
}
}
return 0;
}
----------------------------
Edward