-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzzip.cpp
More file actions
45 lines (42 loc) · 753 Bytes
/
zzip.cpp
File metadata and controls
45 lines (42 loc) · 753 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
// wzip.cpp, by Yingwu Zhu
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
if (argc < 2)
{
cout << string(argv[0] + 2) << " file1 [file2 ...]\n";
exit(1);
}
for (int i = 1; i < argc; i++)
{
ifstream fin(argv[i], ifstream::in);
if (!fin.is_open())
{
cout << string(argv[0] + 2) << ": cannot open file\n";
exit(1);
}
int count = 0;
char c, last;
while (fin.get(c))
{
if (count && c != last)
{
cout.write((char *)&count, sizeof(int));
cout.write((char *)&last, 1);
count = 0;
}
last = c;
count++;
}
if (count)
{
cout.write((char *)&count, sizeof(int));
cout.write((char *)&last, 1);
}
fin.close();
}
return 0;
}