12/9/2019 https://rgmcet.codetantra.com/secure/labs-q.jsp?
sNo=34&qId=5b9e68c018b23e0ba62a5e4e&bd=AY3RFZHVEQg%3D%3D&lid=5d…
Exp. Name: Write a C program to Count the Lines, Words and Characters in a given
S.No: 34 Date:
text
Page No:
Aim:
Write a C program to count the lines, words and characters in a given text.
ID: 19091A04P2
At the time of execution, the program should print the following message on the console as:
Enter lines of text (enter END to complete)
For example, if the user gives the input as:
Enter lines of text (enter END to complete)
CodeTantra developed a Robotic tool
In the year 2016
END
then the program should print the result as:
Character = 51, Words = 9, Lines = 2
Note: Do use the printf() function with a newline character ( \n ) at the end.
Source Code:
CountLinesWords.c
#include<stdio.h>
#include<string.h>
void main()
{
char str[70];
int Character=0,Words=0,Lines=0,i;
Rajeev Gandhi Memorial College of Engineering and Technology (Autonomous)
printf("Enter lines of text (enter END to complete)\n");
while(1)
{
gets(str);
if(strcmp(str,"END")==0)break;
Lines++;
Words=Words+1;
for(i=0;str[i]!='\0';i++)
{
if(str[i]== ' ' ||str[i]=='\t') Words++;
Character++;
}
}
printf("Character = %d, Words = %d, Lines = %d\n",Character,Words,Lines);
}
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
https://rgmcet.codetantra.com/secure/labs-q.jsp?sNo=34&qId=5b9e68c018b23e0ba62a5e4e&bd=AY3RFZHVEQg%3D%3D&lid=5d7fba0de9d70… 1/2
12/9/2019 https://rgmcet.codetantra.com/secure/labs-q.jsp?sNo=34&qId=5b9e68c018b23e0ba62a5e4e&bd=AY3RFZHVEQg%3D%3D&lid=5d…
Test Case - 1
Enter lines of text (enter END to complete) CodeTantra developed a Robotic tool
in the year 2016 in the
Page No:
year
2016
and they released in 2017 and
ID: 19091A04P2
they
released
in 2017
END END
Character = 76, Words = 14, Lines = 3
Rajeev Gandhi Memorial College of Engineering and Technology (Autonomous)
https://rgmcet.codetantra.com/secure/labs-q.jsp?sNo=34&qId=5b9e68c018b23e0ba62a5e4e&bd=AY3RFZHVEQg%3D%3D&lid=5d7fba0de9d70… 2/2