Counting the number of characters is important because almost all the text boxes that rely on user input have certain limitations on the number of characters that can be inserted. For example, the character limit on a Facebook post is 63,206 characters. Whereas, for a tweet on Twitter the character limit is 140 characters and the character limit is 80 per post for Snapchat.
Determining character limits become crucial when the tweet and Facebook post updates are being done through API’s.
Note: This program would not run on online compilers. Please make a text (.txt) file on your system and give its path to run this program on your system.
Approach: The characters can be counted easily by reading the characters in the file using getc() method. For each character read from the file, increment the counter by one.
Below is the implementation of the above approach:
Note: The text file used to run this code can be downloaded from here
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C program to copy contents of one file to another file
- C program to check whether the file is JPEG file or not
- C Program to count number of lines in a file
- Write a C program that displays contents of a given file like 'more' utility in Linux
- C Program to print contents of file
- C Program to merge contents of two files into a third file
- C program to delete a file
- C Program for Lower Case to Uppercase and vice-versa in a file
- LEX program to add line numbers to a given file
- C Program to find size of a File
- Lex program to take input from file and remove multiple spaces, lines and tabs
- C program to find and replace a word in a File by another given word
- C program to print odd line contents of a File followed by even line content
- C program to append content of one text file to another
- isspace() in C/C++ and its application to count whitespace characters
- C program to print characters without using format specifiers
- Lex program to count the number of lines, spaces and tabs
- C program to count number of vowels and consonants in a String
- fopen() for an existing file in write mode
- Implement your own tail (Read last n lines of a huge file)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.