Chinaunix首页 | 论坛 | 博客
  • 博客访问: 358397
  • 博文数量: 53
  • 博客积分: 139
  • 博客等级: 入伍新兵
  • 技术积分: 589
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-27 01:55
个人简介

学习linux,学习编程。

文章分类

全部博文(53)

文章存档

2019年(1)

2018年(4)

2016年(4)

2014年(11)

2013年(33)

分类: C/C++

2018-04-07 15:13:40

这里有一个简单的C语言程序,它的功能是在一行里只显示一个单词。该程序只显示ASCII定义的可打印的字符。

点击(此处)折叠或打开

  1. #include <stdio.h>

  2. #define IN 1 // in the word
  3. #define OUT 0 // out of the word

  4. // output format: one word in a line , version 1.0.1
  5. main()
  6. {
  7.     int c, state;

  8.     state = OUT;
  9.     while ((c = getchar()) != EOF) {
  10.         if (c == ' ' || c == '\n' || c == '\t')
  11.             state = OUT;
  12.         else if (state == OUT) {
  13.             state = IN;
  14.             putchar('\n');
  15.         }
  16.         if (c > ' ' && c < '\x7f')
  17.             putchar(c);
  18.     }
  19. }

这是一张简单的图片,显示了这个程序的内容:


附件:是C语言原程序。为了能够上传附件,将文件名后缀改成了txt。
onewordaline.txt



阅读(1357) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~