C language
-
Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *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
-
Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *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
-
Write a C program to Count the Lines, Words and Characters in a given text *Write a C program to count the lines, words and characters in a given text. *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
Read a line, fgets[^] is your friend. If the line read is exactly
END
than your task is complete: report the line, word and character count. On the other hand, if the line read is not the termination one, then increment the line count, and get the first character (incrementing the character count): if it is a blank then set a flagwas_blank = 1;
and go on. If it is not a blank then increment the word count and clear the flag:was_blank = 0;
. Go on with the next character (if any): increment the character count and if the character is-
a blank then set
was_blank = 1;
-
not a blank then, depending on the
was_blank
flag increment the word count (or do nothing), eventually clear the flag:was_blank = 0;
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-