-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
45 lines (37 loc) · 872 Bytes
/
Copy pathcommon.cpp
File metadata and controls
45 lines (37 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
/* extern variables */
int line, column;
FILE *openFile(const char *fileName, const char *mode) {
FILE *fp = fopen(fileName, mode);
column = 0;
line = 1;
if (fp == NULL) {
cout << "Could not open file:" << fileName;
exit(1);
}
return fp;
}
void copyFile(const char *source, const char *destination) {
FILE *f1 = openFile(source, "r");
FILE *f2 = openFile(destination, "w");
char buf[1000];
while (size_t size = fread(buf, 1, sizeof(buf) / sizeof(buf[0]), f1)) {
fwrite(buf, 1, size, f2);
}
fclose(f1);
fclose(f2);
}
char next(FILE *fp) {
column++;
return fgetc(fp);
}
void shift(FILE *fp, long int m) {
column = column + m;
fseek(fp, m, SEEK_CUR);
}
char peek(FILE *fp) {
char c = fgetc(fp);
ungetc(c, fp);
return c;
}