C program to count number of characters words and lines




















Before that, you … Read More. In this program, we will create a separate function for each … Read More. Fascinating Number Program in C In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not.

You may go through … Read More. Peterson Number in C In this tutorial, we will learn about the Peterson number and check if the number is Peterson or not in C. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. C code to count the number of characters, words and lines in a file Ask Question. Asked 2 years, 10 months ago. Active 2 years, 10 months ago.

Viewed times. Improve this question. Faith Faith 17 5 5 bronze badges. Suppose the input file doesn't end with a newline. And it is int main void. Add a comment.

Create 3 counter variable for the count of words, lines and characters in the string. Using for loop search for a space ' ' in the string and consecutively increment the variable count for words. Using for loop search for a characters except space and new line in the string and consecutively increment a variable count for characters.

Repeat step 3,4,5 until the loop reaches to the end of the string. Check for the corner cases discussed above and do accordingly. Print all the values of the counter. We are going to take character array of size for input. It is up to the programmer and the need of the problem. A thought must have gazed in your mind that how can we be so sure that the input will be given exactly characters, so yes we are not sure of that and to deal with that we are going to use scanf with formatting.

Let me explain its advantages and usage. It helps to ignore a particular operator. There are many variations of this problem, and there are few more corner cases where the interviewer may ask you to do changes, but the most important thing is to understand the approach of solving the question, so that it will not be difficult for you make small modifications asked by your interviewer.

Please login to view or add comment s. C program to count the number of lines, words and characters Jan. Become an Author Submit your Article. It's Simple and Conceptual. Get Python course for



0コメント

  • 1000 / 1000