Program to calculate Number of words,lines,characters

#include "stdio.h"

int main()
{
int c,w=0,ch=0,l=0;
while((c=getchar())!=-1)
{
++ch;
if (c=='\n')
{
++l;
++w;
}
if (c==' ')
++w;
}
printf("characters = %d, words = %d, lines = %d",ch,w,l);
}

No comments:

Post a Comment