1-6 验证 getchar() != EOF 的值是 0 还是 1.
#include <stdio.h>
int
main()
{
printf("getchar() != EOF is: %d", (getchar() != EOF));
return 0;
}
引用
中文怎么了
getchar() != EOF is: 1
Process returned 0 (0x0) execution time : 11.685 s
*
中文怎么了 为输入内容
1-7 编写一个打印 EOF 值得程序
#include <stdio.h>
int
main()
{
printf("EOF is: %d", EOF);
return 0;
}
引用
EOF is: -1
Process returned 0 (0x0) execution time : 0.015 s
1-8 编写一个统计空格, 制表符与换行符个数的程序.
int
main()
{
int c, n = 0;
while ((c = getchar()) != EOF) {
if (c == '\n' || c == ' ' || c == '\t') {
n++;
}
}
printf("n = %d", n);
return 0;
}
引用
HELLO HELLO HELLO HELLO HELLO
ASSSSS
AASADASD
asdasdadasd
^Z
n = 8
Process returned 0 (0x0) execution time : 28.280 s
1-9 编写一个将输入复制到输出的程序, 并将其中连续的多个空格用一个空格代替.
#include <stdio.h>
int
main()
{
int c, p;
while ((c = getchar()) != EOF) {
if (c != ' ' || (p != ' ')) {
putchar(c);
}
p = c;
}
return 0;
}
引用
H E L L O
H E L L O
^Z
Process returned 0 (0x0) execution time : 25.480 s
* 加了个下划线, 直接 quote 第一个空格不显示
1-10 编写一个将输入复制到输出的程序, 并将其中的制表符替换为 \t, 把回退符替换为 \b, 把反斜杠替换为 \\. 这样可以将制表符和回退符以可见的方式显示出来.(未解决)
/*
* TODO
* 我做不出来, getchar() 居然要等一个回车, 难道我记错了?
*/
#include <stdio.h>
int
main()
{
int c;
/* c = getchar() 不加括号编译会有警告 */
while ((c = getchar())) {
/* 意义不大, 为了让程序在收到 EOF 可以退出 */
if (c == EOF) {
return 0;
}
if (c == '\t') {
printf("\\t");
} else if (c == '\b') {
printf("\\b");
} else if (c == '\\') {
printf("\\\\");
} else {
putchar(c);
}
}
return 0;
}
分享到:
相关推荐
Some Final Comments on the MOV Instructions<br><br>4.9 Laboratory Exercises<br>4.9.1 The UCR Standard Library for 80x86 Assembly Language Programmers<br>4.9.2 Editing Your Source Files<br>4.9.3 The ...
够权威<br><br>Brian W.Kernighan && Dennis M.Ritchie
<br>Published by Prentice-Hall in 1988 <br><br>ISBN 0-13-110362-8 (paperback)<br>ISBN 0-13-110370-9 <br><br>Contents<br>Preface <br>Preface to the first edition <br>Introduction <br>Chapter 1: A ...
The C Programming Language[C程序设计语言] -- (英文第2版) -- B.W.Kernighan & D.M.Ritchie 著.pdf
《the c programming language》第6单元课本程序《the c programming language》第6单元课本程序《the c programming language》第6单元课本程序《the c programming language》第6单元课本程序《the c programming ...
The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 目录结构: Contents Preface Preface ...
The ANSI C Programming Language (Kernighan & Ritchie) EN 英文原版<br><br>学习标准C语言最好的入门书,结合Unix高级编程,将C语言讲得非常透彻<br>Chapter 1- A Tutorial Introduction<br>Chapter 2- Types,...
Oracle---Fundamentals of the Java Programming Language, Java SE 6 Ed 1 课程学习文档
<The C Programming Language中文译本>
The C Programming language--C程序设计语言--双语完整版! 很经典的教材!祝你好运!有什么问题留言!
Chapter 3 - Tools for Accessing SQL Server <br> Chapter 4 - Introducing Transact-SQL Language <br> Chapter 5 - Data Retrieval <br> Chapter 6 - SQL Functions <br> Chapter 7 - Aggregation and Grouping ...
Chapter 3 - Tools for Accessing SQL Server <br> Chapter 4 - Introducing Transact-SQL Language <br> Chapter 5 - Data Retrieval <br> Chapter 6 - SQL Functions <br> Chapter 7 - Aggregation and Grouping ...
中文版 Apple 官方 Swift 教程《The Swift Programming Language》
最经典的c语言教程,不用多介绍了吧,The C Programming Language, The C Programming Language, K&C, 发明人写的。
Chapter 3 - Tools for Accessing SQL Server <br> Chapter 4 - Introducing Transact-SQL Language <br> Chapter 5 - Data Retrieval <br> Chapter 6 - SQL Functions <br> Chapter 7 - Aggregation and Grouping ...
《C程序设计语言》是由C语言的设计者Dennis M. Ritchie和著名计算机科学家Brian W. Kernighan编写的一部介绍标准C语言及其程序设计方法的权威性经典著作。全面、系统地讲述了C语言的各个特性及程序设计的基本方法,...
The Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming. Objective-C is defined as a small but powerful set of extensions to the standard ...
chap6-The Keyboard<br> chap7-The Mouse<br> chap8-The Timer<br> chap9-Child Window Controls<br> chap10-Menus and Other Resources<br> chap11-Dialog Boxes<br> chap12-The Clipboard<br>Section 2:More ...
Problem - Design - Solution 第二部分<br>Table of Contents <br> ASP.NET 2.0 Website Programming—Problem - Design - Solution <br> Foreword <br> Introduction <br> Chapter 1 - Introducing the Project: ...
《the c programming language》第4单元课本程序《the c programming language》第4单元课本程序《the c programming language》第4单元课本程序《the c programming language》第4单元课本程序《the c programming ...