Answer to Exercise 1-12, page 21
Solution by Richard Heathfield
Write a program that prints its input one word per line.
#include <stdio.h>
int main(void)
{
int c;
int inspace;
inspace = 0;
while((c = getchar()) != EOF)
{
if(c == ' ' || c == '\t' || c == '\n')
{
if(inspace == 0)
{
inspace = 1;
putchar('\n');
}
/* else, don't print anything */
}
else
{
inspace = 0;
putchar(c);
}
}
return 0;
}
'The C Programming Language' 카테고리의 다른 글
Chapter 1 - A Tutorial Introduction 14 (0) | 2009.03.25 |
---|---|
Chapter 1 - A Tutorial Introduction 13 (0) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 11 (0) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 10 (1) | 2009.03.25 |
Chapter 1 - A Tutorial Introduction 9 (0) | 2009.03.25 |