#include <fstream>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
constexpr std::size_t minfields{33};
std::optional<std::vector<std::string>> splitStr(const std::string &line,
const char delimiter = ',')
{
std::vector<std::string> splitLine;
splitLine.reserve(minfields);
std::istringstream ss(line);
std::string buf;
unsigned field{0};
while (std::getline(ss, buf, delimiter)) {
splitLine.push_back(buf);
if (field == 3 && buf[0] != 'E' && buf[0] != 'T') {
return std::nullopt;
}
++field;
}
if (splitLine.size() < minfields)
return std::nullopt;
return splitLine;
}
void copy_selective(std::istream &in, FILE *out)
{
std::string line;
while (std::getline(in, line)) {
auto split = splitStr(line, ';');
if (split) {
fprintf(out,
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
split.value()[0].c_str(),
",",
split.value()[1].c_str(),
",",
split.value()[3].c_str(),
",",
split.value()[4].c_str(),
",",
split.value()[5].c_str(),
",",
split.value()[6].c_str(),
",",
split.value()[10].c_str(),
",",
split.value()[9].c_str(),
",",
split.value()[11].c_str(),
",",
split.value()[7].c_str(),
",",
split.value()[32].c_str(),
"\n");
}
}
}
int main(int argc, char *argv[])
{
if (argc >= 3) {
std::ifstream inFile(argv[1]);
FILE *outFile{fopen(argv[2], "w")};
copy_selective(inFile, outFile);
}
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxvcHRpb25hbD4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+Cgpjb25zdGV4cHIgc3RkOjpzaXplX3QgbWluZmllbGRzezMzfTsKCnN0ZDo6b3B0aW9uYWw8c3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+PiBzcGxpdFN0cihjb25zdCBzdGQ6OnN0cmluZyAmbGluZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IGNoYXIgZGVsaW1pdGVyID0gJywnKQp7CiAgc3RkOjp2Z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ICAgc3BsaXQudmFsdWUoKVs0XS5jX3N0cigpLAogICAgICAgICAgICAgICIsIiwKICAgICAgICAgICAgICBzcGxpdC52YWx1ZSgpWzVdLmNfc3RyKCksCiAgICAgICAgICAgICAgIiwiLAogICAgICAgICAgICAgIHNwbGl0LnZhbHVlKClbNl0uY19zdHIoKSwKICAgICAgICAgICAgICAiLCIsCiAgICAgICAgICAgICAgc3BsaXQudmFsdWUoKVsxMF0uY19zdHIoKSwKICAgICAgICAgICAgICAiLCIsCiAgICAgICAgICAgICAgc3BsaXQudmFsdWUoKVs5XS5jX3N0cigpLAogICAgICAgICAgICAgICIsIiwKICAgICAgICAgICAgICBzcGxpdC52YWx1ZSgpWzExXS5jX3N0cigpLAogICAgICAgICAgICAgICIsIiwKICAgICAgICAgICAgICBzcGxpdC52YWx1ZSgpWzddLmNfc3RyKCksCiAgICAgICAgICAgICAgIiwiLAogICAgICAgICAgICAgIHNwbGl0LnZhbHVlKClbMzJdLmNfc3RyKCksCiAgICAgICAgICAgICAgIlxuIik7CiAgICB9CiAgfQp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgaWYgKGFyZ2MgPj0gMykgewogICAgc3RkOjppZnN0cmVhbSBpbkZpbGUoYXJndlsxXSk7CiAgICBGSUxFICpvdXRGaWxle2ZvcGVuKGFyZ3ZbMl0sICJ3Iil9OwogICAgY29weV9zZWxlY3RpdmUoaW5GaWxlLCBvdXRGaWxlKTsKICB9Cn0K
Main.java:1: error: illegal character: '#'
#include <fstream>
^
Main.java:1: error: class, interface, or enum expected
#include <fstream>
^
Main.java:2: error: illegal character: '#'
#include <optional>
^
Main.java:3: error: illegal character: '#'
#include <sstream>
^
Main.java:4: error: illegal character: '#'
#include <string>
^
Main.java:5: error: illegal character: '#'
#include <vector>
^
Main.java:9: error: class, interface, or enum expected
std::optional<std::vector<std::string>> splitStr(const std::string &line,
^
Main.java:13: error: class, interface, or enum expected
splitLine.reserve(minfields);
^
Main.java:14: error: class, interface, or enum expected
std::istringstream ss(line);
^
Main.java:15: error: class, interface, or enum expected
std::string buf;
^
Main.java:16: error: class, interface, or enum expected
unsigned field{0};
^
Main.java:17: error: class, interface, or enum expected
while (std::getline(ss, buf, delimiter)) {
^
Main.java:19: error: class, interface, or enum expected
if (field == 3 && buf[0] != 'E' && buf[0] != 'T') {
^
Main.java:21: error: class, interface, or enum expected
}
^
Main.java:23: error: class, interface, or enum expected
}
^
Main.java:26: error: class, interface, or enum expected
return splitLine;
^
Main.java:27: error: class, interface, or enum expected
}
^
Main.java:32: error: class, interface, or enum expected
while (std::getline(in, line)) {
^
Main.java:34: error: class, interface, or enum expected
if (split) {
^
Main.java:59: error: class, interface, or enum expected
}
^
Main.java:67: error: class, interface, or enum expected
FILE *outFile{fopen(argv[2], "w")};
^
Main.java:68: error: class, interface, or enum expected
copy_selective(inFile, outFile);
^
Main.java:69: error: class, interface, or enum expected
}
^
23 errors