Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9275697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:38:54+00:00 2026-06-18T16:38:54+00:00

Is it possible to handle data type mismatch exceptions in C? In C++ and

  • 0

Is it possible to handle data type mismatch exceptions in C?

In C++ and other higher-level languages, the code is usually surrounded by try…catch. However, since there is no exception handling mechanism in C, how do we handle data type mismatch exceptions?

For instance, let us assume that I have a program that requires the user to enter an integer number. If the user hits an alphabetic character by mistake, the program crashes. How can I take care of this in C?

Here is some sample code:

#include "stdafx.h"

void main()
{
    int x = 0;
    printf("Hello World!\n\n");
    printf("Please enter an integer: ");
    scanf("%d", &x);
    printf("\n");
    printf("The integer entered is %d", x);
    printf("\n\n");
    printf("Press any key to exit!");
    getchar();
    getchar();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:38:55+00:00Added an answer on June 18, 2026 at 4:38 pm

    I am going to assume that you are using scanf to handle input. the program should not crash. You need to read the manual page for scanf and in the section return values it tells you that the function returns the number of items matched. You compare this number with what is expected. If they differ you take the appropriate action.

    EDIT

    Some code for Matthew and Bart:

    int i;
    
    if (scanf("%d", &i) == 1)
    {
        printf("You have entered %d\n", i);
    }
    else
    {
        printf("You have entered an invalid number\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a website/ vpath, it's possible to handle the Application_Error event to catch errors
Possible Duplicate: handle json request in PHP The following: $.ajax({ type: 'POST', url: 'receive-json.php',
I'm trying to verify I understand Core Data relationships and/or possibly how to handle
Is it possible to handle the call of an URL Scheme inside the same
Is it possible to handle this event in some way? What happens in terms
Is it possible to handle such events as: Ctrl + mouse left button click;
Is it possible to handle a mouseDown event in VB.Net (2008) regardless of the
Possible Duplicate: Open/handle Word documents like SharePoint I´ve developed one website where it is
is it possible elasticsearch to handle queries containing typos . Example trying to query
I'm trying to create a good way to handle all possible collisions between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.