c program to count line,black space ,charaters and words.
`#include<stdio.h>
void main()
{
char ch;
int line=1,blank=0,w=0,wflag=0;
do
{
ch=getchar();
if(ch=='\n')
{line++;wflag=0;}
if(ch==' ')
{blank++;wflag=0;}
if(ch!='\n'&&ch!=' '&&ch!='.'&&wflag==0)
{
w++;
wflag=1;
}
}
while(ch!=’.’);
printf("\n\nNumber of Line in Given Paragraph is : %d",line);
printf("\n\nNumber of Blank Spaces in Given Paragraph is : %d",blank);
printf("\n\nNumber of Words in Given Paragraph is : %d\n",w);
}
`
This is the code for your problem. if you have any doubts add comments…
2 Likes
That guy got his homework done for free!
4 Likes
i want it from file opration.
- declare a file pointer like this “File fp;”
- Then open a file which has content “fp=open(“test.txt”,“r”);”
- Then read characters like this “c = fgetc(fp);”
- When content of file ends last fgetc(fp) returns “EOF”.