Find Missing Character in C, C++, Java & Python – Code with Explanation & Examples in Short and Simple

   

C Program

#include <stdio.h>
#include <ctype.h>

int main() {
    char str[100];
    int count = 0;
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);

    for (int i = 0; str[i] != '\0'; i++) {
        if (isdigit(str[i])) {
            count++;
        }
    }

    printf("Total digits in string: %d\n", count);
    return 0;
}

C Output

Input:
Hello123World45

Output:
Total digits in string: 5



C++ Program

#include <iostream>
#include <cctype>
using namespace std;

int main() {
    string str;
    int count = 0;
    cout << "Enter a string: ";
    getline(cin, str);

    for (char c : str) {
        if (isdigit(c)) {
            count++;
        }
    }

    cout << "Total digits in string: " << count << endl;
    return 0;
}

C++ Output

Input:
MyPass2025Code

Output:
Total digits in string: 4



JAVA Program

import java.util.Scanner;

public class CountDigitsInString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String str = sc.nextLine();
        int count = 0;

        for (int i = 0; i < str.length(); i++) {
            if (Character.isDigit(str.charAt(i))) {
                count++;
            }
        }

        System.out.println("Total digits in string: " + count);
    }
}

JAVA Output

Input:
RoomNo42Block7

Output:
Total digits in string: 3



Python Program

s = input("Enter a string: ")
count = sum(1 for c in s if c.isdigit())
print("Total digits in string:", count)

Python Output

Input:
Python3IsCool2025

Output:
Total digits in string: 6



Explanation
Example
If the input string is "Welcome2025ToMSBTE", we have normal characters interleaved with digits. Scanning character by character, we see that these are the digits (2, 0, 2, 5) and we count them. The answer is 4. It's simple: iterate through the string, check each character with a digit-check function (isdigit in C, C++, Python or Character.isDigit in Java), and maintain a counter.

Real-Life Analogy
Suppose you are reading a message in which numbers are embedded within words, such as "Your OTP is 4729 and has a validity of 10 minutes." If someone asked you to count the number of numbers in the sentence, you would not look at the letters and symbols but count only the numeric digits. Likewise, the program ignores everything except digits and counts them. It's akin to photocopying an assorted shopping list with both item titles and counts—your job is merely to record the numerical counts. 

Why It Matters
Digit counting in a string may seem elementary, but it finds real-world applications. For instance, during form input validation of phone numbers, Aadhaar numbers, or passwords, you might need to validate whether the input has digits. During natural language processing, digit counting aids the extraction of numerical data embedded in SMS messages. In cyber security, applications check whether passwords have a minimum of one digit, and digit counting verifies conformity to strong password guidelines.

Learning Insights
This exercise educates newbies on string manipulation beyond print. It teaches character classification, conditional checks, and looping over data. It is also a nice introduction to library method such as isdigit() or Character.isDigit(). What matters more is that it demonstrates how little tasks such as counting digits can be abstracted into bigger problems such as parsing text and extracting data.

Interview Use Case
In programming interviews, these kinds of questions challenge your string manipulation and pattern recognition skills. The interviewer may also expand the question, requiring you not only to give the number of digits but also to get the digits, build the number, or add them up. For example, if the input is "abc123x4," you may be required to output 127. This evolution assists interviewers in assessing problem-solving as well as code flexibility.

Real-World Applications
Banking Systems: Retrieving numeric information such as account numbers from user input.

E-commerce: Parsing product codes that have numeric values.

Chatbots: Extracting dates, prices, or IDs embedded in text messages.

Data Cleaning: Deleting or validating numeric values in text columns.

SEO Optimized Closing Paragraph
Counting digits within a string is one of the most frequent string manipulation issues in programming. For the beginner, it will illustrate how to traverse through strings and make use of the character-checking methods and logic in a simple but effective way. The problem is frequently asked in coding interviews, online coding challenges, and exams as it tests some fundamental skills, including iteration, condition checking, and text parsing. Mastering how to do this in C, C++, Java, and Python forms a solid base for tackling more complex text-processing issues like checking phone numbers, parsing numerical values from logs, and putting security checks into production projects.