1 //++++++++++++++++++++++++++
2 // csum_count.cpp
3 //++++++++++++++++++++++++++
4
5 ///#include head file
6 #include <stdio.h>
7 //#include <stdlib.h>
8
9
10 ///main_entry
11 main(int argc,char *argv[])
12 {
13
14
15 ///declare
16 FILE *out_file;
17 FILE *in_file;
18 int ch;
19 unsigned long word_count;
20 unsigned long checksum;
21
22
23 ///Open rb-file
24 in_file=fopen(argv[1],"rb");
25
26
27 ///Is file
28 if (in_file==NULL)
29 {
30
31
32 ///Prompt error !
33 printf("Cannot open %s\n",argv[1]);
34
35
36 ///main_EXIT
37 return(1);
38
39
40 /// +
41 }//end if
42
43
44 ///Initial value
45 word_count=0;
46 checksum=0;
47
48
49 ///Read a char
50 ch=fgetc(in_file);
51
52
53 ///Loop till EOF
54 while(ch!=EOF)
55 {
56
57
58 ///Increase counter
59 word_count++;
60 checksum=checksum+ch;
61
62
63 ///Read a char
64 ch=fgetc(in_file);
65
66
67 /// +
68 } //end while
69
70
71 ///Display checksum
72 printf("%s " "Checksum = %lx,\n",argv[1] ,checksum);
73
74
75 ///Display ch_count
76 printf("%s " "Character count = %ld \n",argv[1] ,word_count);
77
78
79 ///Close rb-file
80 fclose(in_file);
81
82
83 ///main_end
84 return 0;
85 } //main_end
86
87
This Blog is dedicated to Sir Johnson Lin
C language : Get a file's check sum and character number
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言