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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:25:48+00:00 2026-06-03T16:25:48+00:00

I have a programming assignment and we are asked to create a program in

  • 0

I have a programming assignment and we are asked to create a program in which the user will be able to enter the date in this format dd/mm/year. Then we have to find a way to extract each of those numbers and put in the day, month and year fields in a structure.

I thought to read the whole input of the user as a string and then just select the values of the string that I want. Here is my code.

The structure declaration:

 struct datestructure{
    char day;
   char month;
   char year;
  };

struct prj{
   int ID;
   struct namestructure name;
   struct datestructure date;
   float price;    

 };



 struct prj project[MAX];

And here is the code that I have written.

     char dateinput[11];
 scanf("%s", dateinput);


 printf("%s", dateinput); //making sure that the input is read correctly


 project[n].date.day = dateinput[0]+dateinput[1];


 printf("%s", project[n].date.day );

However this is not working and I am running out of ideas. Could you give me some guidance on how to solve this problem.

Thanks.

  • 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-03T16:25:50+00:00Added an answer on June 3, 2026 at 4:25 pm

    Here are some suggestions:

    1. Consider changing the types of day, month & year to int.
    2. Parse the day, month & year out of your complete date string
    3. Convert each of the day, month & year into integer either using one of the system functions (atoi or strtol etc) or your own logic code.

    Some basic sample for parsing the string (Just an example for you to understand. There are other better methods also):

    char day[3] = {0};
    char month[3] = {0};
    char year[5] = {0};
    
    memcpy(day, dateinput,2);
    memcpy(month,dateinput+3, 2);
    memcpy(year,dateinput+5, 4);
    

    Note: The above code doesn’t take care of erroneous input and considers that day and month having single digits will be enetered with a preceding 0. Ex Input: 07/03/2012. Note the preceding 0 before 7 and 3. First you can try like this and later on improvise by yourself to handle all error scenarios.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm rushing against the clock for a programming assignment in which I have to
I have this programming assignment that converts between meters and feet, and between kilograms
i have a unix c programming assignment in which i do some advanced C
I have an assignment from my programming class, which is very poorly worded... The
hey guys, i have a c++ programming assignment that asks me to create a
for a programming assignment I have been asked to implement a solution to the
I have a school assignment which consists of programming a scanner/lexical analyzer for a
I have an assignment in my C programming class to write a program to
I have got an assignment in which I should program a simple teller machine
I obviously do not 'grok' C++. On this programming assignment, I have hit a

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.