#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_STRING_LENGTH 100
int main(int argc, char **argv)
{
if(argc<2)
{
printf("Provide source file name as command line argument.\n");
exit(1);
}
FILE *fptr;
fptr=fopen(argv[1],"r");
if(fptr==NULL)
{
printf("Unable to open file %s\n",argv[1]);
exit(1);
}
char str[MAX_STRING_LENGTH];
int lineCount=0,emptyLineCount=0,cmntLineCount=0,semiColonLineCount=0;
while(fgets(str,MAX_STRING_LENGTH-1, fptr)!=NULL)
{
lineCount++;
if(strcmp(str,"\n")==0)
{
emptyLineCount++;
continue;
}
if((str[0] == '/') && (str[1] == '/'))
{
cmntLineCount++;
continue;
}
if(str[strlen(str)-1] == ';')
{
semiColonLineCount++;
}
}
fclose(fptr);
printf("No. of line = %d\nNo. of blank line = %d\nNo. of commented line = %d\nNo. of lines ending with semicolon = %d\n",lineCount,emptyLineCount,cmntLineCount,semiColonLineCount);
}