The first time I read this book was a junior year, and now I'm going to reread it again!
Introduction to Chapter I.
1. The only way to learn a new programming language is to use it to write programs.
2. Each program is executed from the beginning of the main function.
3. In the C language, all variables must be declared before they are used.
4. The size of the basic data type in the C language depends on the specific machine.
5. A more complex expression of that type can be used in any situation where the value of a type variable is allowed.
6. The input/output model of the standard library is processed in a character stream, with 0 or more characters in each line, and a newline character at the end.
7. Functions provide an easy way to calculate the encapsulation of a function, which is called by value.
#include <stdio.h>//file copy int main () {int C;while ((c = GetChar ()) = EOF) {Putchar (c);} return 0;}
/* * Write a program that copies the input to the output, and replaces multiple spaces in it with a single space. */#include < Stdio.h>int Main () {int C; int flag = 0; Whether the current character is a space while ((c = GetChar ())! = EOF) {if ((c = = ' && flag = = 0) | | (c! = ")) {Putchar (c); flag =!flag; }} return 0;}
#include <stdio.h> #define IN 1//Word # define out 0///outside Word// Counts the number of rows, the number of words, and the number of characters int main () {int C; int numlines = 0; Number of rows int numwords = 0; Number of words int numcharacters = 0; Number of characters int state = out; while ((c = GetChar ()) = EOF) {++numcharacters; if (c = = ' \ n ') {++numlines; } if (c = = ' | | c = = ' \ t ' | | c = = ' \ n ') {state = out; } else if (state = = out) {state = in; ++numwords; }} printf ("%d\t%d\t%d\n", Numlines, Numwords, numcharacters); return 0;}
#include <stdio.h> #define MAXLINE 1000/* * Read into one line of characters */int getline_s (char *s, int lim) { int c, I; for (i = 0; i < lim-1 && (c = GetChar ())! = EOF && c! = ' \ n '; ++i) { s[i] = c; } if (c = = ' \ n ') { s[i] = c; ++i; } S[i] = ' + '; return i;} /* Copy array */void copy (char *to, char *from) { int i = 0; while ((to[i] = From[i])! = ' + ') { ++i; } } int main () { int len; int max = 0; Char Line[maxline]; Char Longest[maxline]; while (len = getline_s (line, MAXLINE)) > 0) { if (len > Max) { max = len; Copy (longest, line); } } if (Max > 0) { printf ("%s\n", longest); } return 0;}
Cond....
[C + +] reread the C programming Language