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

  • Home
  • SEARCH
  • 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 4543624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:33:26+00:00 2026-05-21T15:33:26+00:00

I am trying to prevent recreating the wheel. I am parsing an input file

  • 0

I am trying to prevent recreating the wheel. I am parsing an input file that has time as one of the values. I need a data structure to hold all of the values of the input file, and instead of creating a custom structure for the time field I want to just use struct tm from ctime.

I’m running into a strange error though, so hopefully one of you can help me out. Here’s my test code (for my proof of concept):

#include <ctime>
#include <cstdio>

int main()
{

int Oldhour = 16;
int OldSecond = 25;
int OldMinute = 20;

time_t seconds;

struct tm * timeinfo;

timeinfo->tm_hour = Oldhour;
timeinfo->tm_min = OldMinute;
timeinfo->tm_sec = OldSecond;


int hour, min, sec;

hour = timeinfo->tm_hour;
min = timeinfo->tm_min;
sec = timeinfo->tm_sec;

printf("%d:%d:%d", hour, min, sec);

return 0;
}

This compiles just fine and it does exactly what I want and prints “16:20:25” so it’s storing the info the way I want. However if I remove the line “time_t seconds;” it crashes immediately.

  • 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-05-21T15:33:27+00:00Added an answer on May 21, 2026 at 3:33 pm

    You need to allocate the structure either on the stack or on the heap with malloc. Specifically, you’re declaring a pointer to the struct without allocating any storage for it.

    Try this:

    #include <ctime>
    #include <cstdio>
    
    int main()
    {
    
    int Oldhour = 16;
    int OldSecond = 25;
    int OldMinute = 20;
    
    time_t seconds;
    
    struct tm timeinfo;
    
    timeinfo.tm_hour = Oldhour;
    timeinfo.tm_min = OldMinute;
    timeinfo.tm_sec = OldSecond;
    
    
    int hour, min, sec;
    
    hour = timeinfo.tm_hour;
    min = timeinfo.tm_min;
    sec = timeinfo.tm_sec;
    
    printf("%d:%d:%d", hour, min, sec);
    
    return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to prevent access to a specific file, not any files with a certain
I'm trying to prevent certain keys from being entered into an input box, but
I'm trying to prevent an associated record from being deleted if it has associated
I am trying to prevent duplicated data to database when the user click the
I'm trying to prevent a javascript file from loading if a user is on
I am trying to declare a variable that has a default value or if
I am trying to prevent line breaking in this Html http://jsfiddle.net/DD3v8/ It happens that
Im trying to prevent users to access special pages with a phaselistener. for that
I'm trying to prevent circular (or even cascading) references in my data, and it
I am trying to prevent data races in a multihreaded server. My problem is

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.