Users Online

· Guests Online: 92

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to Count No of Lines, Blank Lines, Comments in a given

Here is source code of the C Program to count no of lines, blank lines, comments in a given program. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Count No of Lines, Blank Lines, Comments in a given Program
*/
#include <stdio.h>

void main(int argc, char* argv[])
{
int line_count = 0, n_o_c_l = 0, n_o_n_b_l = 0, n_o_b_l = 0, n_e_c = 0;
FILE *fp1;
char ch;
fp1 = fopen(argv[1], "r");

while ((ch = fgetc(fp1))! = EOF)
{
if (ch == '\n')
{
line_count++;
}
if (ch == '\n')
{
if ((ch = fgetc(fp1)) == '\n')
{
fseek(fp1, -1, 1);
n_o_b_l++;
}
}
if (ch == ';')
{
if ((ch = fgetc(fp1)) == '\n')
{
fseek(fp1, -1, 1);
n_e_c++;
}
}
}
fseek(fp1, 0, 0);
while ((ch = fgetc(fp1))! = EOF)
{
if (ch == '/')
{
if ((ch = fgetc(fp1)) == '/')
{
n_o_c_l++;
}
}
}
printf("Total no of lines: %d\n", line_count);
printf("Total no of comment line: %d\n", n_o_c_l);
printf("Total no of blank lines: %d\n", n_o_b_l);
printf("Total no of non blank lines: %d\n", line_count-n_o_b_l);
printf("Total no of lines end with semicolon: %d\n", n_e_c);
}



$ cc file8.c
$ a.out stack_ll.c
Total no of lines: 204
Total no of comment line: 19
Total no of blank lines: 11
Total no of non blank lines: 193
Total no of lines end with semicolon: 66

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.73 seconds
10,837,536 unique visits