prev


Character Arrays:

78.Count words lines characters (12.05.2010)

/*
Program# 78
date : 28-12-2008
Count no.of words,lines and characters
*/

#include <stdio.h>
main(){
char a[100];
int i,l=0,w=0;

i=0;
scanf("%c",&a[i]);
while(a[i]!='$'){
i++;
scanf("%c",&a[i]);
}
a[i]='\0';

i=0;
while(a[i]!='\0'){
if(a[i] == '\n')
l++;

if((a[i] != ' '&& a[i] == ' ')||(a[i] != '\n' && a[i+1] == '\n')||(a[i] != '\t' && a[i+1] == '\t'))
w++; //Need to check into this ????

i++;
}

printf("\n No.of lines : %d",l);
printf("\n No.of words : %d",w);
printf("\n No.of chars : %d",i);
}



next
blog comments powered by Disqus