Waitrud Weber’s blog

things and reminders for memories

Analyzer: Customized Parse: Step Back to the file operator in C:

Step Back to the file operator in C.

.\filerecover.cpp Fri Apr 10 19:35:43 2020

1 ://20200408: created:
2 :#include <stdio.h>
3 :#include <stdlib.h>
4 :
5 :#define CHAR_MAX 256
6 :#define PARSE_NUM 256
7 :
8 :int filesize( FILE *fp ) ;
9 :
10 :// Execution:
11 :// > .\a.exe
12 :// *********************************\filerecover\filerecover_20200409\a.exe
13 :// >
14 :// (which means argv[0} is execution itself.
15 :int main ( int argc, char** argv) {
16 : FILE *fp;
17 : char char_word[CHAR_MAX];
18 : char char_temp_word[CHAR_MAX];
19 : char* filename;
20 :
21 : if ( argc < 1 ) {
22 : printf("error: there is no parameter.");
23 : exit(-1);
24 : }
25 :
26 : printf("%s \r\n", argv[0] );
27 : exit(-1);
28 :
29 : filename = argv[1];
30 :
31 : fp = fopen ( filename, "rb" );
32 : int file_end = filesize ( fp );
33 :
34 : for( int i=0; i<file_end && i<PARSE_NUM; i++ ) {
35 :
36 :
37 : printf("i %d r\n", i );
38 : }
39 :
40 : return 0;
41 :}
42 :
43 ://
44 ://
45 ://
46 ://
47 ://
48 :int filesize( FILE *fp ) {
49 :
50 : fseek(fp, 0L, SEEK_END);
51 : int sz = ftell(fp);
52 :
53 : fseek(fp, 0L, SEEK_SET);
54 :
55 : return sz;
56 :}
57 :
58 :