Advertisement
salron3

Comments

Dec 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. int GetCommentsNumber(FILE* inputFile)
  2. {
  3. int numberOfComments = 0;
  4.     int multylineComment = 0;
  5.     char line[256];
  6.     char currentChar;
  7.  
  8.     while ((currentChar = fgetc(inputFile)) != EOF) //Chete dokato ne stingne krai na faila
  9.     {
  10.         int i = 0;
  11.         while (currentChar != '\n' && currentChar != EOF)//Prochite 1 red
  12.         {
  13.             line[i++] = currentChar; //Zapisva v line
  14.             currentChar = fgetc(inputFile);
  15.         }
  16.  
  17.         line[i] = '\0';
  18.         if (i != 0) //Ima procheten red
  19.         {
  20.             for (size_t j = 0; j < i - 1; j++)
  21.             {
  22.                 if (line[j] == '/' && multylineComment == 0)
  23.                 {
  24.                     if (line[j + 1] == '/')
  25.                     {
  26.                         numberOfComments++;
  27.                     }
  28.                     else if (line[j + 1] == '*')
  29.                     {
  30.                         multylineComment = 1;
  31.                     }
  32.                 }
  33.                 else if (line[j] == '*' && line[j + 1] == '/')
  34.                 {
  35.                     multylineComment = 0;
  36.                     numberOfComments++;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     rewind(inputFile);
  42.     return numberOfComments;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement