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. LeetCode-Search in Rotated Sorted Array II

    Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this ...

  2. 【耐克】【空军一号 Nike Air Force 1】【软木塞】

     [高帮 全白 36-45] [空军一号 低帮 36-46] [空军一号 36-45] [Nike Air Force 1 Flyknit 空军中帮飞线系列 全黑 36-44] [耐克空军一号 软木塞 ...

  3. WPF-流文档元素

    1.Block元素 用于分组其他元素 Paragraph是块级别元素,文本段落 Paragraph.Inlines集合内. 设置第一行缩进量Paragraph.TextIndet 2.Inline元素 ...

  4. 定制个性化码表技术 ibus

    在不同用户的工作环境中,都会根据各自使用的字符集的不同,而需要定制优化各自的输入法码表,例如,在GB18030中的大量汉字,或许因为输入法码表的老旧,而难于利用自己熟悉的“五笔”方法快速录入,同样,需 ...

  5. jquery 百度搜索

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. Zedboard安装桌面系统ubuntu及opencv(1)

    最近一直在搞板子,想帮Zedboard安装一个opencv谁知道困难重重,而且网络几乎没有任何资料可以参考,只有陆佳华的<嵌入式软硬件协同设计实战指南>可以参考. 但是这本书讲得不清不楚, ...

  7. 关于 iOS 10 中 ATS 的问题

    本文于 2016 年 11 月 28 日按照 Apple 最新的文档和 Xcode 8 中的表现进行了部分更新. WWDC 15 提出的 ATS (App Transport Security) 是 ...

  8. [MongDB] 主从架构--官方极力不推荐

    一.缘由: 看着数据库大家庭都有主从模式,想着Mongodb应该也不会落下.但从官网看来,先是早先舍弃了Master-Master模式,现在又在不推荐 Master-Slave模式,这是要标新立异呀. ...

  9. hive 基本语法

    本来想讲自己用到的写出来了,结果发现一个比较全面的文章已经介绍过了,那我就不在重新发明轮子了,我也跟着学习一下. 转自:http://jeffxie.blog.51cto.com/1365360/31 ...

  10. 使用compass编译sass

    1.初始化项目 compass create test(项目名称),会在当前目录下创建test子目录,test的子目录下有config.gb文件,sass和stylesheets文件夹. 2.编写sa ...