fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. unsigned int SLOC(std::fstream *inFile);
  5.  
  6. int main()
  7. {
  8. std::fstream filestream ("input.txt", std::fstream::in | std::fstream::out);
  9. if(filestream.is_open()){
  10. std::cout << SLOC(&filestream) << '\n';
  11. }
  12.  
  13. filestream.close();
  14.  
  15. return 0;
  16. }
  17.  
  18. unsigned int SLOC( std::fstream *inFile)
  19. {
  20. unsigned loc = 0;
  21. bool singleLineComment = false;
  22. bool multiLineComment = false;
  23. unsigned int stringLen = 0;
  24. char c;
  25.  
  26. do{
  27. inFile->get(c);
  28.  
  29. if(c == '/' && ( inFile->peek() == '/' || inFile->peek() == '*') && !multiLineComment){
  30. if(inFile->peek() == '/'){
  31. singleLineComment = true;
  32. //inFile->get(c);
  33. }
  34. else if(inFile->peek() == '*'){
  35. multiLineComment = true;
  36. //inFile->get(c);
  37. }
  38. }
  39. else{
  40. if(multiLineComment){
  41. if(c == '*' && inFile->peek() == '/'){
  42. inFile->get(c);
  43. multiLineComment = false;
  44. }
  45. }
  46. else if (singleLineComment){
  47. if(c == '\n')
  48. singleLineComment = false;
  49. }
  50. else{
  51. if(c !=' ' && c != '\n' && c != ';')
  52. ++stringLen;
  53. else if(c == ';' && stringLen){
  54. ++loc;
  55. stringLen = 0;
  56. }
  57. }
  58.  
  59. }
  60.  
  61.  
  62. }while(!inFile->eof());
  63.  
  64. return loc;
  65. }
  66.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty