Exercise 1-9

作者在 2009-02-13 11:35:01 发布以下内容
/*Write a program to copy its input to its output,
 *replacing each string of one or more blanks by a single blank*/
#include <stdio.h>
 
#define OUT 1 /* outside the word */
#define IN  0 /* inside the word */
 
int main(void)
{
    int c,state;
   
    state = OUT;
    while ((c = getchar()) != EOF)
    {
          if (state == OUT && c == ' ')
          {
                    state= IN;
                    putchar(c);
          }
          else if (c != ' ')
          {
              putchar(c);
              state = OUT;
          }
          else
              ;
    }
   
    return 0;
}
文章评论,共0条
游客请输入验证码
浏览27699次
文章归档