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
|
#include <set>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
int main()
{
const std::set<std::string> token {"int", "byte", "short", "char", "float", "long", "struct", "int*", "byte*", "short*", "char*",
"float*", "long*", "void", "double"};
std::ifstream ifs("prog.txt");
if (!ifs)
return (std::cout << "Cannot open file\n"), 1;
size_t varCount {};
size_t funcCount {};
for (std::string line; std::getline(ifs, line); ) {
std::istringstream iss(line);
for (std::string word; iss >> word; )
if (token.find(word) != token.end())
if (line.find("(") != std::string::npos && line.find(";") == std::string::npos)
++funcCount;
else
++varCount;
}
std::cout << "\nVariables: " << varCount;
std::cout << "\nFunctions: " << funcCount;
}
|