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 8673963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:35:18+00:00 2026-06-12T19:35:18+00:00

i need to calculate the age then in c programming how can i do

  • 0

i need to calculate the age then in c programming how can i do “user input filtering” at scanf.

 main()
 {
 scanf("%d %d %d ,month,date, year);
 --------;
 printf("your age is"...);
 }

here the user can enter alphabets or some symbols how to filter them in c?

  • 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-12T19:35:19+00:00Added an answer on June 12, 2026 at 7:35 pm

    If by filtering, you mean remove the offending characters, you can either read lines in buffers and inspect them, or use a quick hack like this:

    scanf("%d%*[^0-9]%d%*[^0-9]%d", &month, &day, &year);
    

    where the * after % means to read and throw away and the ^0-9 in brackets means any character that is not 0 through 9. Possible pitfall: if the first character is unwanted, scanf fails. If you put a %*[^0-9] in the beginning, then input beginning with a number fails.

    Alternatively, ask the user for proper input in case of failure (in previous case also you should check for the return value of scanf):

    while (scanf("%d %d %d", &month, &day, &year) != 3)
    {
        printf("bad input! Retry\n");
        /* possibly flush the line: */
        while (!feof(stdin) && fgetc(stdin) != '\n');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate date (year, month, day) which is (for example) 18 working
I need to calculate the age of a customer from their date of birth.
How can i calculate year from entering my age using php. example: i am
I need to calculate the number of FULL month in SQL, i.e. 2009-04-16 to
I want to calculate the current Age from Date of Birth in my Oracle
Need to calculate a date before a given time (let it be 10 years)
I need to calculate the number of days passed between 2 dates using java.util.Date,
I store user date of birth in timestamp. I calculate timestamp with javascript. day
I need to calculate if someone is over 18 from their date of birth
I have date when someone is born, and I need to calculate with JavaScript

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.