/*
C program to read a C file in current directory and count statements,
brackets and included files
*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *file;
char *str,ch;
int st,br,in;
st=br=in=0;
clrscr();
printf("Enter C file name:");
gets(str);
file=fopen(str,"r");
if(file)
{
while(1)
{
ch=getc(file);
if(ch=='(' || ch==')' || ch=='{' || ch=='}' || ch=='[' || ch==']')
br++;
if(ch==';')
st++;
if(ch=='#')
in++;
if(ch==EOF)
break;
}
fclose(file);
printf("Number of brackets:%d\n",br);
printf("Number of statements:%d\n",st);
printf("Number of included files:%d",in);
}
else
printf("Invalid File!");
getch();
}
C program to read a C file in current directory and count statements,
brackets and included files
*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *file;
char *str,ch;
int st,br,in;
st=br=in=0;
clrscr();
printf("Enter C file name:");
gets(str);
file=fopen(str,"r");
if(file)
{
while(1)
{
ch=getc(file);
if(ch=='(' || ch==')' || ch=='{' || ch=='}' || ch=='[' || ch==']')
br++;
if(ch==';')
st++;
if(ch=='#')
in++;
if(ch==EOF)
break;
}
fclose(file);
printf("Number of brackets:%d\n",br);
printf("Number of statements:%d\n",st);
printf("Number of included files:%d",in);
}
else
printf("Invalid File!");
getch();
}
No comments:
Post a Comment