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. Get Jenkins job build queue length

    Jenkins API doesn’t provide the job build queue length. Hence, it seems we have to parse the html to ...

  2. HDU 5966 Guessing the Dice Roll

    题意有 N≤10 个人,每个猜一个长度为L≤10的由1−6构成的序列,保证序列两两不同.不断地掷骰子,直到后缀与某人的序列匹配,则对应的人获胜.求每个人获胜的概率. 思路:建立trie图,跑高斯消元. ...

  3. Pyside开篇杂记

    最近学习刚开始学习pyside,基本了解了一些类的用法,个人感觉就接触而言与pyqt并无本质区别. 双方资料基本可以相互借鉴,个人更倾向与pyside,查阅资料时也经常会在pyqt内得到解决方案. 之 ...

  4. kuangbin_SegTree D (POJ 2528)

    讲道理我之前暂时跳过染色的题是因为总觉得有什么很高端的算法来query 直到我做了F题(ZOJ 1610)才发现就是个暴力统计.....也对 也就几万个长度单位而已.... F就不po上来了 选了有点 ...

  5. (转) WTF is computer vision?

        WTF is computer vision? Posted Nov 13, 2016 by Devin Coldewey, Contributor   Next Story   Someon ...

  6. dw的流体网格布局

    在设计视图拖拽 在插入面板中选择插入流体网格布局标签 在对话框中如果不选中新建行复选框 如果总的列数是5列 一行的列宽和上一行的列宽加起来没有5列的话,下一行会上浮

  7. 一个简易的反射类库NMSReflector

    转自:http://blog.csdn.net/lanx_fly/article/details/53914338 背景简介 以前看过一些代码,是简单的读取SqlReader然后赋值给Model,我不 ...

  8. 1、rhel 6.5 系统准备

    1.启动.关闭.重置服务    (rhel7 为 systemctl) [root@rhel-6 ~]# service atd status #关闭atd服务 atd 已停 [root@rhel-6 ...

  9. 在CentOS上安装和部署Shiny Server

    1.安装R: sudo yum install R 2.安装Shiny的R包: sudo su - \ -c "R -e \"install.packages('shiny', r ...

  10. IOS-指定返回Modal的控制器presentViewController

    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion: ...