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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:02+00:00 2026-06-10T00:33:02+00:00

I am writing a pretty basic C program to try to better understand how

  • 0

I am writing a pretty basic C program to try to better understand how the time library works and to learn more about C. The problem is, I’m getting a segfault when I return 0 at the end of my main function. Here is the text of the program:

#include <stdio.h>
#include <time.h>

main()
{
    time_t *now;
    time(now);
    struct tm *tp = localtime(now);
    printf("%s", asctime(tp));
    return 0;
}

Using gdb I can see that on line 10 (return 0) everything has gone fine so far, and my only two variables are now and tp. Here is what happens when I print them:

(gdb) print now
$7 = (time_t *) 0x7fff5fbff838
(gdb) print tp
$8 = (struct tm *) 0x7fff7b13e470
(gdb) print *now
$9 = 1345338893
(gdb) print *tp
$10 = {
  tm_sec = 53, 
  tm_min = 14, 
  tm_hour = 21, 
  tm_mday = 18, 
  tm_mon = 7, 
  tm_year = 112, 
  tm_wday = 6, 
  tm_yday = 230, 
  tm_isdst = 1, 
  tm_gmtoff = -14400, 
  tm_zone = 0x100802518 "EDT"
}

Everything seems just fine. But then when I hit n,

Cannot access memory at address 0x50303e0d
0x0000000050303e0d in ?? ()

I don’t understand what could be causing this error. Returning 0 at the end of main has never hurt me before, and the memory address doesn’t match up with either of the ones I’m using. When I run my program in Terminal, I get Segmentation fault: 11.
The only thing I can think of is that it’s something to do with the operating system, which makes sense for several reasons – the relatively low memory address, and the error being thrown by the O.S. trying to access the memory address on the stack to return to. Why could this be happening, though? I don’t know much about Operating Systems (I’m learning about C so I can skip a course requirement and take the Operating Systems course offered by my university) so maybe this is a really easy question. I tried running another C program in the same directory, and it went just fine.

  • 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-10T00:33:03+00:00Added an answer on June 10, 2026 at 12:33 am

    You didn’t initialize now or maybe you wanted to initialize it on the stack, like

    #include <stdio.h>
    #include <time.h>
    
    main()
    {
        time_t now;
        time(&now);
        struct tm *tp = localtime(&now);
        printf("%s", asctime(tp));
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems to be a pretty basic concept that I don't understand. In writing
I'm about 11 months into writing a pretty extensive HTML5-ready video deployment library for
I'm pretty new to C# and Visual Studio. I'm writing a small program that
all. I'm pretty new to C++, and I'm writing a small library (mostly for
I'm writing a pretty basic webserver (well, trying) and while it's now serving HTML
I am writing a pretty basic php app and have created a pretty big
I'm writing a pretty basic application in python (it's only one file at the
I'm currently writing some pretty basic code for a shopping cart on a webpage
I am busy writing a program in Visual Basic .NET and I have a
I am currently writing a system for publishing tutorials about basic PHP. However, I

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.