Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
58
01-04.md
58
01-04.md
|
|
@ -20,39 +20,41 @@ libraries do their work. In other words, *know the territory*!
|
|||
|
||||
**LISTING 1.4 L1-4.C**
|
||||
|
||||
/*
|
||||
* Program to calculate the 16-bit checksum of the stream of bytes
|
||||
* from the specified file. Obtains the bytes one at a time via
|
||||
* getc(), allowing C to perform data buffering.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
```c
|
||||
/*
|
||||
* Program to calculate the 16-bit checksum of the stream of bytes
|
||||
* from the specified file. Obtains the bytes one at a time via
|
||||
* getc(), allowing C to perform data buffering.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
main(int argc, char *argv[]) {
|
||||
FILE *CheckFile;
|
||||
int Byte;
|
||||
unsigned int Checksum;
|
||||
main(int argc, char *argv[]) {
|
||||
FILE *CheckFile;
|
||||
int Byte;
|
||||
unsigned int Checksum;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
printf("usage: checksum filename\n");
|
||||
exit(1);
|
||||
}
|
||||
if ( (CheckFile = fopen(argv[1], "rb")) == NULL ) {
|
||||
printf("Can't open file: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if ( argc != 2 ) {
|
||||
printf("usage: checksum filename\n");
|
||||
exit(1);
|
||||
}
|
||||
if ( (CheckFile = fopen(argv[1], "rb")) == NULL ) {
|
||||
printf("Can't open file: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Initialize the checksum accumulator */
|
||||
Checksum = 0;
|
||||
/* Initialize the checksum accumulator */
|
||||
Checksum = 0;
|
||||
|
||||
/* Add each byte in turn into the checksum accumulator */
|
||||
while ( (Byte = getc(CheckFile)) != EOF ) {
|
||||
Checksum += (unsigned int) Byte;
|
||||
}
|
||||
/* Add each byte in turn into the checksum accumulator */
|
||||
while ( (Byte = getc(CheckFile)) != EOF ) {
|
||||
Checksum += (unsigned int) Byte;
|
||||
}
|
||||
|
||||
/* Report the result */
|
||||
printf("The checksum is: %u\n", Checksum);
|
||||
exit(0);
|
||||
}
|
||||
/* Report the result */
|
||||
printf("The checksum is: %u\n", Checksum);
|
||||
exit(0);
|
||||
}
|
||||
```
|
||||
|
||||
#### Know When It Matters {#Heading10}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue