[The following is a code listing from the article "Error Messages and Documentation", by S. L. Sanders]
//============================ skipcomm ================================
// Skip one or more contiguous comments (C or C++ syntax).
// Upon entry, currline[csi] is the first char of an opening comment
// delimiter. Upon returning, currline[csi] is the first nonblank
// following the last in a series of contiguous comments, or it is an
// unexpected EOF.
//
//  Return: 0=Normal
//          1=Error
//
//            Copyright (c) Sanders-Indev, Inc, 1997:
// Commercial use of any kind is prohibited without written consent of
// the owner. Personal and teaching use is permitted.
//======================================================================
short skipcomm()

{ //BEGIN skipcomm
short i;   //General index
char  cpp; //Boolean: TRUE = C++ syntax; FALSE = C syntax

       /*--Process all lines that begin with comment or continuation--*/
while(TRUE){ //Do all comment lines
  csi+=2; //Skip past 2-char opening comment delimiter (either C or C++)
  cpp=(currline[csi-1]=='/'); //Set C++ comment indicator
  while(!COMMCLOS&&!feof(inf)) //Advance csi to closing delimiter
    if(cpp) //Comment uses C++ syntax
      if(EOL)
        break; //Endline ends C++ comment, so immediately
      else     //  exit "Advance csi to closing delimiter" loop.
        csi++;
      else //Comment uses C syntax
        if(EOL)
          READLINE(return(1))
            //return(1) is executed by NEXTLINE if read fails.
        else
          csi++;

                   /*--Check for premature EOF--*/
  if(feof(inf)&&(!cpp)){ //Comment closing not found
    printf("\nError: EOF looking for closing comment "
           "delimiter in input file %s.",infnam);
    fprintf(wrkf,"\nError: EOF looking for closing comment "
                 "delimiter in input file %s.",infnam);
    //This indicates that the input is not an error-free C source.
    err=1; //Indicate bad input file
    return(1);
    } //END Comment closing not found

         /*--End of comment reached-- check for contiguous one--*/
  if(!cpp)
    csi+=2;  //Skip past the 2-char closing comment delimiter
  SKIPBLNK(currline,csi) //Skip any blanks following comment
  if(EOL){ //Continuation or newline follows comment
    i=linectr; //Save the line count (to detect skipped lines)
    READLINE(return(1))
      //return(1) is executed by NEXTLINE if it can't read the file.
    if(linectr>i+1||!COMMOPEN(csi))
      break; //Line after comment just done is not a comment, so
             //  immediately exit "Do all comment lines" loop.
    } //END Continuation or newline follows comment
  else //Non-blank char follows comment on same line
    if(!COMMOPEN(csi))
      break; //Not a contiguous comment on same line, so
             //  immediately exit "Do all comment lines" loop.
  } //END Do all comment lines

                         /*--Normal return--*/
//ASSERT: currline[csi] is the first nonblank following the last in
//        a series of contiguous comments, or a premature EOF reached.
return(0);
} //END skipcomm
//======================================================================
Back to main article.