軟體實驗: C-Lab7 虞台文
Lab7 Issues Lab 7-1 On-Off bits counting Lab 7-2 ACSII File Verification
ACSII Table
軟體實驗: C-Lab7 Lab 7-1
Lab 7-1: On-Off Bits Counting Write a pair of functions, bitson and bitsoff, that return the number of bits that are on and off in a file. Use the shorthand bit-manipulation operators.
Lab 7-1: On-Off Bits Counting Example: Boy.txt Good boy. Goodboy.Goodboy on off
Lab 7-1: On-Off Bits Counting Example: Boy.txt Good boy. Goodboy.Goodboy on off There are 38 on-bits and 34 off-bits in file Boy.txt.
Bit On/Off Test mask & mask & & & & & & & On Off On Off
bitson/bitsoff int bitson(char c) returns number of on-bit in c int bitsoff(char c) returns number of off-bit in c
軟體實驗: C-Lab7 Lab 7-2
Lab 7-2: ACSII File Verification Write a program that verifies that every character in its input is an ASCII character. A non-ASCII character (a character with its high-order bit set) causes an error message containing its octal code and position in the file (line number and character). We can use this program to verify that a file contains only ASCII characters before trying to compress it with our compression program (Figure 6.2.7).
ACSII Table
Lab 7-2: ACSII File Verification Example: Boy.txt Good boy. Boy.txt is an ASCII file.
Lab 7-2: ACSII File Verification Example: Girl.txt Good girl. She is a 美人. Girl.txt is a non-ASCII file. 美 人 AC = = 0254 A non-ASCII char (0254) appears at position 10 of line 2.