solutions/The C Programming Language/1.9.c

31 lines
373 B
C
Raw Normal View History

2024-04-17 19:31:45 -04:00
#include <stdio.h>
#define NORMAL 0
#define SPACEBARING 1
// trimming excessive spacebars down to one
2024-04-17 19:31:45 -04:00
main()
{
int c;
int state = NORMAL;
while ((c = getchar()) != EOF)
{
if (state == NORMAL)
{
putchar(c);
if (c == ' ')
state = SPACEBARING;
}
if (state == SPACEBARING)
{
if (c != ' ')
{
state = NORMAL;
putchar(c);
}
}
}
}