#include <iostream>
#include <fstream>
unsigned int SLOC_1(std::fstream &inFile);
unsigned int SLOC_2(std::fstream &inFile);
int main()
{
std::fstream filestream ("input.txt", std::fstream::in | std::fstream::out);
if(filestream.is_open()){
std::cout << SLOC_2(filestream) << '\n';
}
filestream.close();
return 0;
}
unsigned int SLOC_1( std::fstream &inFile)
{
unsigned int sloc = 0;
std::string loc;
inFile >> loc;
while(!inFile.eof()){
if (loc.length() > 0){
if(loc.at(loc.length()-1) == ';')
++sloc;
}
inFile >> loc;
};
if (loc.length() > 0){
if(loc.at(loc.length()-1) == ';')
++sloc;
}
return sloc;
}
unsigned int SLOC_2( std::fstream &inFile)
{
unsigned loc = 0;
bool commentBlock = false;
bool singleLineComment = false;
bool multiLineComment = false;
unsigned int stringLen = 0;
char c;
char aux;
do{
inFile.get(c);
if(c == ';'){
if (commentBlock == false){
if(stringLen != 0){
++loc;
stringLen = 0;
}
}
else{
if (singleLineComment == true)
singleLineComment = false;
}
}
else if (c == '/'){
aux = inFile.peek();
if (aux == '/'){
commentBlock = true;
singleLineComment = true;
inFile.get(c);
}
else if(aux == '*'){
commentBlock = true;
multiLineComment = true;
inFile.get(c);
}
}
else if ((c == '*') && (multiLineComment)){
aux = inFile.peek();
if(aux == '/'){
commentBlock = false;
multiLineComment = false;
inFile.get(c);
}
}
else
++stringLen;
}while(!inFile.eof());
return loc;
}