Line | |
---|
1 | #include "File.h"
|
---|
2 |
|
---|
3 | #include <stdlib.h>
|
---|
4 |
|
---|
5 | File::File(const char *name, const char *flags)
|
---|
6 | {
|
---|
7 | f = fopen(name, flags);
|
---|
8 | if (!f)
|
---|
9 | printf("WARNING: Cannot open '%s'\n", name);
|
---|
10 | }
|
---|
11 |
|
---|
12 | File::~File()
|
---|
13 | {
|
---|
14 | fclose(f);
|
---|
15 | }
|
---|
16 |
|
---|
17 | char File::Getc() const
|
---|
18 | {
|
---|
19 | return fgetc(f);
|
---|
20 | }
|
---|
21 |
|
---|
22 | int File::Eof() const
|
---|
23 | {
|
---|
24 | return feof(f);
|
---|
25 | }
|
---|
26 |
|
---|
27 | void File::Seek(long pos) const
|
---|
28 | {
|
---|
29 | fseek(f, pos, SEEK_SET);
|
---|
30 | }
|
---|
31 |
|
---|
32 | void File::Reset() const
|
---|
33 | {
|
---|
34 | fseek(f, 0, SEEK_SET);
|
---|
35 | }
|
---|
36 |
|
---|
37 | long File::Tell() const
|
---|
38 | {
|
---|
39 | return ftell(f);
|
---|
40 | }
|
---|
41 |
|
---|
42 | long File::Size() const
|
---|
43 | {
|
---|
44 | long l = ftell(f);
|
---|
45 | fseek(f, 0, SEEK_END);
|
---|
46 | long s = ftell(f);
|
---|
47 | fseek(f, l, SEEK_SET);
|
---|
48 | return s;
|
---|
49 | }
|
---|
50 |
|
---|
51 | char *File::Gets(char *c, int cnt) const
|
---|
52 | {
|
---|
53 | for (int i=0; i<cnt; i++)
|
---|
54 | *c++=fgetc(f);
|
---|
55 | *c='\0';
|
---|
56 |
|
---|
57 | return c;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void File::Newline() const
|
---|
61 | {
|
---|
62 | int g;
|
---|
63 | do g=fgetc(f);
|
---|
64 | while (g!=0x0A && g!=EOF);
|
---|
65 | }
|
---|
66 |
|
---|
67 | int File::Geti(int cnt) const
|
---|
68 | {
|
---|
69 | char *c = new char[cnt+1];
|
---|
70 | Gets(c, cnt);
|
---|
71 | int result = atoi(c);
|
---|
72 | delete c;
|
---|
73 | return result;
|
---|
74 | }
|
---|
75 |
|
---|
76 | float File::Getf(int cnt) const
|
---|
77 | {
|
---|
78 | char *c = new char[cnt+1];
|
---|
79 | Gets(c, cnt);
|
---|
80 | float result = atof(c);
|
---|
81 | delete c;
|
---|
82 | return result;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void File::Skip(int cnt) const
|
---|
86 | {
|
---|
87 | char *c = new char[cnt+1];
|
---|
88 | Gets(c, cnt);
|
---|
89 | delete c;
|
---|
90 | }
|
---|
91 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.