-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileHandling25.c
52 lines (51 loc) · 1.45 KB
/
FileHandling25.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* C Program to Collect Statistics of a Source File like Total Lines,
* Total no. of Blank Lines, Total no. of Lines ending with Semicolon
*/
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char *argv[]) /* Command line Arguments */
{
int ncount = 0, ccount = 0, scount = 0, blank = 0;
char ch;
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL)
{
perror("Error Occured");
}
else
{
while(1)
{
ch = fgetc(fp);
if (ch == EOF)
{
break;
}
if (ch == 10)
{
ncount++;
if (ch = fgetc(fp) == '\n')
{
fseek(fp, -1, 1); /* shifting offset of the file to previous position */
blank++;
}
}
else if (ch == 59)
{
scount++;
}
else if (ch == '/' || ch == '*')
{
ccount++;
}
}
}
printf("\nThe Total number of lines are %d", ncount);
printf("\nThe Total number of Commented lines are %d", ccount);
printf("\nThe Total number of blank lines are %d", blank);
printf("\nThe total number of lines that end with Semicolon %d", scount);
printf("\nThe length of Actual code is %d ", ncount-blank-ccount);
fclose(fp);
}