Logo 
Search:

GuestBook of Amit Dhane

 
Enter your message (HTML allowed after you earn 150 points)
VIPIN SINGH
  VIPIN SINGH from India      Aug 08
/* Write a C program to count the lines, words and characters in a given text*/
can you explain how the while loop is terminated here
Program

main()
{
char line[81], ctr;
int i,c,
end = 0,
characters = 0,
words = 0,
lines = 0;
printf(“KEY IN THE TEXT.\n”);
printf(“GIVE ONE SPACE AFTER EACH WORD.\n”);
printf(“WHEN COMPLETED, PRESS ‘RETURN’.\n\n”);
while( end == 0)
{
/* Reading a line of text */
c = 0;
while((ctr=getchar()) != ‘\n’)
line[c++] = ctr;
line[c] ='\0';
/* counting the words in a line */
if(line[0] =='\0')
break ;
else
{
words++;
for(i=0; line[i] != '\0';i++)
if(line[i] == ‘ ‘ || line[i] == ‘\t’)
words++;
}
/* counting lines and characters */
lines = lines +1;
characters = characters + strlen(line);
}