C Exercises: Counts the number of characters left in the file
60. Count Characters Until End of File
Write a C program that takes user input and counts the number of characters until the end of the file.
Note: On Linux systems and OS X, the character to input to cause an EOF is CTRL+D. For Windows, it's CTRL+Z
This C program takes input from the user until the end of the file (EOF) is encountered and counts the number of characters entered. It prompts the user with instructions on how to signal EOF based on the operating system. Then, it enters a loop where each character input increments a counter variable. Once EOF is detected, it prints the total count of characters entered.
Sample Solution:
C Code:
Output:
Input characters: On Linux systems and OS X EOF is CTRL+D. For Windows EOF is CTRL+Z. Number of Characters: 10
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to count the number of characters in input until EOF and display the total count.
- Write a C program to read input until EOF and count only the alphanumeric characters.
- Write a C program to count characters from a file until EOF and then output the count to another file.
- Write a C program to count the number of characters until EOF and calculate the average ASCII value of the characters.
C Programming Code Editor:
Previous: Check whether an n digits number is Armstrong or not.
Next: Count the upper-case, lower-case and other characters
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics