码迷,mamicode.com
首页 > 其他好文 > 详细

C - The C Answer (2nd Edition) - Exercise 1-12

时间:2015-07-25 10:45:29      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:exercise 1-12

/* Write a program that prints its input one word per line. */

#include <stdio.h>

#define IN  1  /* inside a word  */
#define OUT 0  /* outside a word */

/* print input one word per line */
main()
{
	int c, state = OUT;
	while((c = getchar()) != EOF)
	{
		if(c == ' ' || c == '\n' || c == '\t')
		{
			if(state == IN)
			{
				putchar('\n');  /* finish the word */
				state = OUT;
			}
			else if(state == OUT)
			{
				state = IN;  /* beginning of word */
				putchar(c);
			}
			else  /* inside a word */
			{
				putchar(c);
			}
		}
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

C - The C Answer (2nd Edition) - Exercise 1-12

标签:exercise 1-12

原文地址:http://blog.csdn.net/troubleshooter/article/details/47053329

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!