-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (75 loc) · 2.21 KB
/
Copy pathmain.cpp
File metadata and controls
87 lines (75 loc) · 2.21 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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
void writeToFile(const string& filename, const string& content) {
string folder = "output/";
string fullPath = folder + filename;
ofstream outFile(fullPath, ios::app);
if (!outFile) {
cerr << "Error opening file for writing: " << fullPath << endl;
return;
}
outFile << content << '\n';
outFile.close();
}
void parseToMd(vector<int>& lineNumbers) {
string line;
ifstream MyFile("readmes.txt");
if (!MyFile.is_open()) {
cerr << "Failed to open readmes.txt" << endl;
return;
}
//variables
int i = 0;
string repoName;
while (getline(MyFile, line)) {
if (!lineNumbers.empty() && i == lineNumbers[0]) {
auto pos = line.find(':');
if (pos != string::npos) {
repoName = line.substr(pos + 1);
repoName = repoName.erase(repoName.length() - 4);
cout << "Processing repository: " << repoName << endl;
}
cout << "Error creating file for line: " << i << endl;
lineNumbers.erase(lineNumbers.begin()); // Remove the first line number after processing
} else {
writeToFile(repoName + ".md", line);
}
++i;
}
}
int main() {
string line;
ifstream MyFile("readmes.txt");
if (!MyFile.is_open()) {
cerr << "Failed to open readmes.txt" << endl;
return 1;
}
int i = 0;
map<string, int> repoLineMap;
vector<int> lineNumbers;
// Read file line-by-line
while (getline(MyFile, line)) {
if (line.find("REPO:") != string::npos) {
auto pos = line.find(':');
if (pos != string::npos) {
repoLineMap[line] = i;
lineNumbers.push_back(i); // Store line number for the repository
}
}
++i;
}
MyFile.close();
for (const auto& [file, lines] : repoLineMap) {
cout << file << ": " << lines << endl;
}
for (const auto& lineNum : lineNumbers) {
cout << "Line number: " << lineNum << endl;
}
parseToMd(lineNumbers);
return 0;
}