1-9 :

Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank. 

point : change the entry of space putchar when there has met a space already.

#include <stdio.h>
main(){
    ;
    ;
    while((c = getchar()) != EOF){
        if(c == ' '){
            ){
                putchar(c);
                inspace = ;
            }
        }
        else{
            inspace = ;
            putchar(c);
        }
    }
}

count the numbers of word:

 #include <stdio.h>
 #define IN 1  //no ";"
 #define OUT 0

 main(){
     int c ;
     int state = OUT;
     int nc, nw, nl;
     nc = nw = nl = ;  //注意初始化 

     while((c = getchar()) != EOF){
         nc ++;
         if(c == '\t')
             nl++;
         if(c == ' ' || c == '\t' || c == '\n') {
             state = OUT;
         }
         else if(state == OUT){  //if state is OUT here, means in the word, chage state and ++nw
             state = IN;
             nw++;
         }
     }
     printf("%d %d %d",nc, nw, nl);
 }

design a program output the result that every line contains only a word

 #include <stdio.h>
 #define IN 1  //no ";"
 #define OUT 0

 main(){
     int c ;
     ;
     while((c = getchar()) != EOF){
         if(c == ' ' || c == '\t' || c == '\t'){
             ){
                 inspace = ;
                 putchar('\n');
             }
         }
         else{
             inspace = ;
             putchar(c);
         }
     }
     ;
 }

The C Programming Language Exercise的更多相关文章

  1. The Go Programming Language. Notes.

    Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...

  2. iOS Swift-元组tuples(The Swift Programming Language)

    iOS Swift-元组tuples(The Swift Programming Language) 什么是元组? 元组(tuples)是把多个值组合成一个复合值,元组内的值可以使任意类型,并不要求是 ...

  3. iOS Swift-控制流(The Swift Programming Language)

    iOS Swift-控制流(The Swift Programming Language) for-in 在Swift中for循环我们可以省略传统oc笨拙的条件和循环变量的括号,但是语句体的大括号使我 ...

  4. iOS Swift-简单值(The Swift Programming Language)

    iOS Swift-简单值(The Swift Programming Language) 常量的声明:let 在不指定类型的情况下声明的类型和所初始化的类型相同. //没有指定类型,但是初始化的值为 ...

  5. Java Programming Language Enhancements

    引用:Java Programming Language Enhancements Java Programming Language Enhancements Enhancements in Jav ...

  6. The Swift Programming Language 英文原版官方文档下载

    The Swift Programming Language 英文原版官方文档下载 今天Apple公司发布了新的编程语言Swift(雨燕)将逐步代替Objective-C语言,大家肯定想学习这个语言, ...

  7. The Swift Programming Language 中文翻译版(个人翻新随时跟新)

    The Swift Programming Language --lkvt 本人在2014年6月3日(北京时间)凌晨起来通过网络观看2014年WWDC 苹果公司的发布会有iOS8以及OS X 10.1 ...

  8. [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01

    注:CocoaChina翻译小组已着手此书及相关资料的翻译,楼主也加入了,多人协作后的完整译本将很快让大家看到. 翻译群:291864979,想加入的同学请进此群哦.(本系列不再更新,但协作翻译的进度 ...

  9. Questions that are independent of programming language. These questions are typically more abstract than other categories.

    Questions that are independent of programming language.  These questions are typically more abstract ...

随机推荐

  1. Chapter 1: Design the application architecture

    1.1 Plan the application layers 提到了repository pattern,SoC(Separation of Concern), 进而提及MVC,Action/Act ...

  2. Servlet执行流程和生命周期【慕课网搬】

    Servlet执行流程(GET方式为例) 首先用户客户端浏览器发出Get方式(点击超链接方式)向浏览器发出请求. 服务器接收到客户端点击超链接,接收到GET请求之后,服务器到WEB.xml中<s ...

  3. Hibernate3 和Hibernate4 在配置文件上的区别

    在使用hibernate之前要首先对hibernate进行一些基础的配置信息,像映射文件XXX.hbm.xml  XXX代表当前的domain的模型类名 <?xml version=" ...

  4. css3 animation-fill-mode 对布局的影响

    问题描述:在小米手机上,animation-fill-mode设置为 both时,在手机上的web页面会超出屏幕宽度,出现滚动条. 解决方法:animation-fill-mode设为none. .p ...

  5. Linux-Rsync服务器/客户端搭建实战

    一.需求 每晚汇总各机器的操作日志,同步到主服务器进行日志分析. 二.基础知识 rsync 分为服务器端.客户端,服务器端搭建比客户端辛苦一些(也是很简单). rsync 服务器是指以 deamon ...

  6. oracle11g重置system密码,外二

    来自:http://lukeview.blog.51cto.com/508652/912124 win+r,输入sqlplus /nolog,回车SQL> conn /as sysdba已连接: ...

  7. [Linux] - Docker制作nginx+php

    使用Docker制作nginx+php的镜像,这里的镜像是centos + nginx 1.9.7 + php 5.6.14 首先下载到nginx和php: nginx-1.9.5.tar.gz 下载 ...

  8. MyBatis学习(一)、MyBatis简介与配置MyBatis+Spring+MySql

    一.MyBatis简介与配置MyBatis+Spring+MySql 1.1MyBatis简介 MyBatis 是一个可以自定义SQL.存储过程和高级映射的持久层框架.MyBatis 摒除了大部分的J ...

  9. C# 自动部署之附加数据库

    转自心存善念 原文 C# 自动部署之附加数据库 看着别人的网站能够自动安装,数据库自动附加,觉得很神奇很向往,但是始终米有去手动实践. 网上找了下资料,发现实现起来其实很简单 直接code priva ...

  10. mysql重复记录的查询删除方法

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select   peopleId from  ...