-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissingfcfilessorting.cpp
More file actions
114 lines (100 loc) · 2.4 KB
/
Copy pathmissingfcfilessorting.cpp
File metadata and controls
114 lines (100 loc) · 2.4 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
using namespace std;
int l=0;
#define a textfile[l]
#define b textfile[l+1]
#define c textfile[l+2]
#define d textfile[l+3]
#define e textfile[l+4]
int length;
bool myfunction (string i, string j) {
return (i==j);
}
vector<string> readingfile(fstream &temp, int &nooflines)
{
vector<string> lines;
if (temp.good())
{
l=0;
length=0;
temp.seekg (0, temp.end);
length = temp.tellg();
temp.seekg (0, temp.beg);
char * buffer = new char [length];
//cout << "Reading " << length << " characters... ";
// read data as a block:
temp.read (buffer,length);
string textfile(buffer);
//cout<<textfile<<endl;
string line;
nooflines=0;
for(;l<length;l++)
{
if(a=='\n' && l<length-1)
{
lines.push_back(line);nooflines++;
line="";
}
else if(l==length-1)
{
lines.push_back(line);nooflines++;
line="";
}
else
{
line+=textfile[l];
}
}
delete[] buffer;
cout<<endl;
textfile="";
}
else
{
cout<<"End of file reached for some reason"<<endl;
}
return lines;
}
vector<string> sortingfiles(vector<string> v)
{
vector<string>::iterator it;
vector<string> myvector (v.size());
it=unique_copy (v.begin(),v.end(),myvector.begin());
sort (myvector.begin(),it);
it=unique_copy (myvector.begin(), it, myvector.begin(), myfunction);
myvector.resize( distance(myvector.begin(),it) );
sort(myvector.begin(),myvector.end());
return myvector;
}
void writingfiles(string name,vector<string> &v, int &nooflines)
{
fstream temp;
temp.open("temp4.txt",fstream::in|fstream::out|fstream::trunc);
for(int q=0;q<nooflines;q++)
temp<<v[q]<<endl;
temp.close();
remove(name.c_str());
if(rename("temp4.txt",name.c_str()));
else
perror( "Error renaming file" );
remove("temp4.txt");
}
int main()
{
fstream tfile1;
string filename1="missingtnofcorrectfilelist.txt";
tfile1.open(filename1.c_str(),fstream::in|fstream::out);
int nooffile1list=0;
vector<string> fcfilelist;
fcfilelist=readingfile(tfile1,nooffile1list);
fcfilelist=sortingfiles(fcfilelist);
writingfiles(filename1,fcfilelist,nooffile1list);
return 0;
}